Oracle查询干货语句
Oracle甲骨文,是一个神圣不可侵犯的数据库。代表雄心,宏伟。作为一名软件测试工程师,需要了解部分oracle查询语句,那么小编,为大家介绍一部分常用的查询语句和函数。 select*from scott.emp; 1 dense_rank()分析函数(查找每个部门工资最高前三名员工信息)

select*from(selectdeptno,ename,sal,dense_rank()over(partitionbydeptnoorderbysaldesc)afromscott.emp)wherea<=3orderbydeptnoasc,saldesc; 结果: 2 rank()分析函数(运行结果与上语句相同)

select*from(selectdeptno,ename,sal,rank()over(partitionbydeptnoorderbysaldesc)afromscott.emp)wherea<=3orderbydeptnoasc,saldesc; 结果: 3 row_number()分析函数(运行结果与上相同)

select*from(selectdeptno,ename,sal,row_number()over(partitionbydeptnoorderbysaldesc)afromscott.emp)wherea<=3orderbydeptnoasc,saldesc; 4 rowsunboundedpreceding分析函数(显示各部门的积累工资总和) selectdeptno,sal,sum(sal)over(orderbydeptnoascrowsunboundedpreceding)积累工资总和fromscott.emp;

结果: 5查看所有用户 select*fromdba_users; selectcount(*)fromdba_users; select*fromall_users; select*fromuser_users; select*fromdba_roles; 查看用户系统权限 select*fromdba_sys_privs; select*fromuser_users; 查看用户对象或角色权限 select*fromdba_tab_privs; select*fromall_tab_privs; select*fromuser_tab_privs; 查看用户或角色所拥有的角色 select*fromdba_role_privs; select*fromuser_role_privs; rownum:查询10至12信息 select*fromscott.empawhererownum<=3anda.empnonotin(selectb.empnofromscott.empbwhererownum<=9); 结果: 5rowid;查询重复数据信息 select*fromscott.empawherea.rowid>(selectmin(x.rowid)fromscott.empxwherex.empno=a.empno); 6根据rowid来分页(一万条数据,查询10000至9980时间大概在0.03秒左右) select*fromscott.empwhererowidin(selectridfrom(selectrownumrn,ridfrom(selectrowidrid,empnofromscott.emporderbyempnodesc)whererownum<10)wherern>=1)orderbyempnodesc; 地址:北京昌平区北七家镇南七家广利福源二层尚脑教育 电脑:010-59418061 课程咨询官方网站:www.litboy.cnwww.litboy.net
扫一扫关注官方微信公众号:

软件测试入门