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

参考原文https://www.cnblogs.com/fighter007/p/8287780.html

查询列表

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;
 
 


猜你喜欢

转载自www.cnblogs.com/bbq668/p/12969570.html