当前位置:Gxlcms > 数据库问题 > oracle数据库之数据插入、修改和删除

oracle数据库之数据插入、修改和删除

时间:2021-07-01 10:21:17 帮助过:3人阅读

select * from classinfo;   --用于查询班级表的sql 

select * from studentinfo;   --用于查询学生表的sql

 

向数据表中插入数据

insert into classinfo(classid,classname) values(01,‘测试一班‘);
insert into classinfo(classid,classname) values(02,‘测试二班‘);
insert into classinfo(classid,classname) values(03,‘测试三班‘);
insert into classinfo(classid,classname) values(04,‘测试四班‘);
commit;

--commit  是一次性提交到数据库保存,不commit就不会真正存储到数据库中。
--rollback 是回滚操作,代表的意思就是不commit就可以回滚到上一次操作


结果

技术图片

 

 

单条插入:

insert into studentinfo(studentid,studentname,studentsex,studentage,studenttel,studentaddress,classid)
values (1, ‘张山‘, ‘男‘, 15, ‘13789895566‘, ‘北京‘,1);

 

多条数据插入:

insert into studentinfo values(2,‘李四‘,‘男‘,18,‘1325655563‘,‘南昌‘,2);

insert into studentinfo values(3,‘王五‘,‘男‘,‘25‘,‘13855223322‘,‘深圳‘,3);

insert into studentinfo values(4,‘丽丽‘,‘女‘,‘23‘,‘13256232236‘,‘新疆‘,4);

 

第二种的方式比第一种更加的方便,如果明确要往表中插入数据,可以省掉values前面的列名

技术图片

 

 

修改张山的性别为女:
update  studentinfo set  studentsex=‘女‘ where studentid=1;
select * from studentinfo;


修改某几列数据:
update studentinfo set studentname=‘李五‘,studentsex=‘女‘,studentage=15 where studentid=2;
commit;
select * from studentinfo;

对数据进行加运算,将张山的年龄增加10岁:
update studentinfo set studentage=studentage+10 where studentid=1;
commit;
乘运算:
update studentinfo set studentage=studentage*3 where studentid=3;
commit;

根据id删除数据:
delete from studentinfo where studentid=1;
commit;

删除表:
删除studentinfo表 即删除整个表中所有的数据
drop table studentinfo;
 
 


 

oracle数据库之数据插入、修改和删除

标签:image   from   修改   sel   date   com   htm   HERE   技术   

人气教程排行