Oracle学习笔记:高级查询

这篇博客详细介绍了Oracle数据库的高级查询技术,包括topN查询、分页查询、exist子句、多行子查询以及处理空值排序等。还探讨了如何随机返回记录、跳过偶数行、获取员工信息及其工资高低对比、连续求和、分部门求和、获取相邻数据行的方法,并讲解了根据子串分组和查询一年天数等实用技巧。同时,博主分享了如何使用数据字典查询用户下的表、表的字段、索引列以及表的约束等。
摘要由CSDN通过智能技术生成

topN查询

select  * from emp where rownum=1   or   rownum=2;
select * from   (select * from emp order by    sal desc) where rownum<5;

分页查询


  1. select * from (select rownum no,e.* from(select * from emp order by sal desc) e where rownum<=5) where no>=3;

  2. select * from (select rownum no,e.* from(select * from emp order by sal desc)e) where no>3 and no<=5;

exist

select * from t1 where exists (select null from t2 where y=x);

for x in (select * from t1)
loop
    if(exist(select null from t2 where y=x.x))

    then
    output the record
     end if;
end loop;

select 1 from dual where null in (0,1,2,null);

多行子查询

select * from emp   
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值