数据操作语句
insert delete update select
1,新增
--添加一条记录
insert into pet(pno,pname,sex)
values(11,'mao','女')
--添加多条记录
begin
insert into pet(pno,pname,sex)
values(11,'mao','女');
insert into pet(pno,pname,sex)
values(12,'','女');
commit;
end;
2,删除
--删除指定记录
delete from pet where pno=11
--将表置空
delete from pet
3,,修改
update pet set sex='母',pno=1994
4,查询
select * from emp
*代表全部的列数据 *可用列内容名代替,以检索所在列
select sal,comm,sal+comm from emp --只要没值就是null。数值型+null=null
--显示每个月实发 用nvl函数
select sal,comm,sal+nvl(comm,0) from emp
--显示年薪
select sal,comm,(sal+nvl(comm,0))*12 from emp
--列的拼接
select * from emp
select '姓名是:'||ename||'工作是:'||job||'月薪是'
||sal as 人员基本信息 from emp
--条件查询
select * from emp where sal !=2000
select * from emp where ename ='SMITH' --值区分大小写,列名不区分 注意空格的影响
--组合条件查询
select *from emp
where sal >1000 and sal<2000
select *from emp
where sal <1000 or sal>2000
select *from emp
where
sal >1000 and sal<2000
or
ename ='SMITH' and sal !=2000 --and 和or 同时使用有优先级所有and低于or
--between and 查询
--请查询出所有工资在6000-8000之间的所有人的信息
select * from person where sal>=6000 and sal<=8000 --每个记录两次扫描
select * from person where sal between 6000 and 8000 --每个记录一次扫描
--in查询
--请查询出所有工资是6000,7000,8000的所有人的基本信息
select * from person where sal=6000 or sal=7000 or sal=8000
select * from person where sal in(6000,7000,8000) --性能更高
--模糊查询like % _
--请查询出所有工资在6000-8000之间,并且姓张的所有人的基本信息
select * from person
where sal between 6000 and 8000 and pname like '%张_%'