Oracle简单增删改查、伪表、运算符

伪表:

--------------------伪表----------------------
--伪表dual的作用:就是为了临时储存函数,运算结果,关键字等没有表的查询的结果的.
-- 查询系统日期
select sysdate from SYS.dual;
-- 查询当前用户
select user from SYS.dual;
-- 查询运算结果
select 6+5,9*8 from SYS.dual;
--------------------伪列rowid----------------------
--Oracle数据库在插入数据的时候,会为每一条数据增加一个唯一标识符.这个唯一标识符就是伪列rowid
select rowid,emp.* from emp;
-- 通过伪列查找数据
select emp.* from emp where rowid='AAAR3sAAEAAAACTAAA';
--------------------伪列rownum----------------------
--Oracle在每一次查询的时候,会为每一条记录增加一个序号.这个序号就是伪列rownum.
select rownum,emp.* from emp;
--Oracle没有像MySQL的limit关键字分页.是通过rownum来实现分页的.
--需求:查询1-9条的数据.
select rownum,emp.* from emp where rownum<=9;
--需求:查询员工表5-10的数据
--rownum不能直接使用>或>=号,如果要使用>或>=号,需求先查出来,再使用子查询来使用.
-- 先取上限
select rownum,emp.* from emp where rownum<=10;
-- 再通过上限查找下限
select * from (select rownum as r,emp.* from emp where rownum<=10) temp where temp.r>=5;
--需求:查询员工的信息,先按部门排序,再取5-10条的数据.
-- 先排序,再使用子查询产生rownum
select rownum,temp.* from (select * from emp order by deptno) temp;
-- 取数据上下限
select * from (select rownum as r,temp.* from (select * from emp order by deptno) temp) temp2 where temp2.r<=10 and temp2.r>=5;

运算符:

--------------------算术运算符----------------------
-- =	等于
-- >	大于
-- <	小于
-- >=	大于等于
-- <=	小于等于
-- !=,<>	不等于,!=与<>功能是一样,<>是SQL标准不等于,所有数据库都支持,!=非标准不等于,并不是所有数据库支持的.
-- in	包含
-- like	模糊匹配
-- betweet  .. and ..	范围
-- in运算符
--需求:查询员工的的部门编号包含10,或者20的员工
select * from emp where deptno in(10,20);
-- betweet  .. and
--需求:查询员工的工资在2000-3000的员工,包括2000与3000
select * from emp where sal between 2000 and 3000;
--需求:查询员工的入职日期1981-04-01至1981-10-10
select * from emp where hiredate between to_date('1981-04-01','yyyy-mm-dd') and to_date('1981-10-10','yyyy-mm-dd');
--------------------逻辑运算符----------------------
-- and	与
-- or	  或
-- not	非
--需求:查询员工的工资在2000-3000的员工,包括2000与3000
select * from emp where sal>=2000 and sal<=3000;
--需求:查询员工的的部门编号包含10,或者20的员工
select * from emp where deptno=10 or deptno=20;
--需求:查询奖金非空的员工
select * from emp where comm is not null;
--------------------集合运算符----------------------
-- 需求:查询员工的工资1000-3000的员工信息,并集员工的工资2000-5000的员工信息
--并集,union
select * from emp where sal between 1000 and 3000 union select * from emp where sal between 2000 and 5000;
--需求:查询员工的工资1000-3000的员工信息,并集员工的工资2000-5000的员工信息,有重复.
--交集(有重复的并集) union all
 select * from (select * from emp where sal between 1000 and 3000 union all select * from emp where sal between 2000 and 5000) order by ename;
--需求:查询员工的工资1000-3000的员工信息减集员工的工资2000-5000的员工信息
--减集:范围是1000-1999,
--减集要减去交集的数据,2000是交集里面的值所以要减掉
--减集:minus
select * from emp where sal between 1000 and 3000 minus select * from emp where sal between 2000 and 5000;


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值