• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • MsSql
  • Mysql
  • oracle
  • MariaDB
  • DB2
  • SQLite
  • PostgreSQL
  • MongoDB
  • Redis
  • Access
  • 数据库其它
  • sybase
  • HBase
您的位置:首页 > 数据库 >oracle > oracle常用sql查询语句部分集合(图文)

oracle常用sql查询语句部分集合(图文)

作者: 字体:[增加 减小] 来源:互联网 时间:2017-05-11

通过本文主要向大家介绍了oracle分页sql语句,oracle sql语句大全,oracle常用sql语句,oracle sql语句,oracle数据库sql语句等相关知识,希望本文的分享对您有所帮助

Oracle查询语句

select * from scott.emp ;

1.--dense_rank()分析函数(查找每个部门工资最高前三名员工信息)

select * from (select deptno,ename,sal,dense_rank() over(partition by deptno order by sal desc) a from scott.emp) where a<=3 order by deptno asc,sal desc ;

结果:

--rank()分析函数(运行结果与上语句相同)

select * from (select deptno,ename,sal,rank() over(partition by deptno order by sal desc) a from scott.emp ) where a<=3 order by deptno asc,sal desc ;

结果:

--row_number()分析函数(运行结果与上相同)

select * from(select deptno,ename,sal,row_number() over(partition by deptno order by sal desc) a from scott.emp) where a<=3 order by deptno asc,sal desc ;

--rows unbounded preceding 分析函数(显示各部门的积累工资总和)

select deptno,sal,sum(sal) over(order by deptno asc rows unbounded preceding) 积累工资总和 from scott.emp ;

结果:

--rows 整数值 preceding(显示每最后4条记录的汇总值)

select deptno,sal,sum(sal) over(order by deptno rows 3 preceding) 每4汇总值 from scott.emp ;

结果:

--rows between 1 preceding and 1 following(统计3条记录的汇总值【当前记录居中】)

select deptno,ename,sal,sum(sal) over(order by deptno rows between 1 preceding and 1 following) 汇总值 from scott.emp ;

结果:

--ratio_to_report(显示员工工资及占该部门总工资的比例)

select deptno,sal,ratio_to_report(sal) over(partition by deptno) 比例 from scott.emp ;

结果:

--查看所有用户

select * from dba_users ;

select count(*) from dba_users ;

select * from all_users ;

select * from user_users ;

select * from dba_roles ;

--查看用户系统权限

select * from dba_sys_privs ;

select * from user_users ;

--查看用户对象或角色权限

select * from dba_tab_privs ;

select * from all_tab_privs ;

select * from user_tab_privs ;

--查看用户或角色所拥有的角色

select * from dba_role_privs ;

select * from user_role_privs ;

-- rownum:查询10至12信息

select * from scott.emp a where rownum<=3 and a.empno not in(select b.empno from scott.emp b where rownum<=9);

结果:

--not exists;查询emp表在dept表中没有的数据

select * from scott.emp a where not exists(select * from scott.dept b where a.empno=b.deptno) ;

结果:

--rowid;查询重复数据信息

select * from scott.emp a where a.rowid>(select min(x.rowid) from scott.emp x where x.empno=a.empno);

--根据rowid来分页(一万条数据,查询10000至9980时间大概在0.03秒左右)

select * from scott.emp where rowid in(select rid from(select rownum rn,rid from(select rowid rid,empno from scott.emp order by empno desc) where rownum<10)where rn>=1)order by empno desc ;

结果:

--根据分析函数分页(一万条数据,查询10000至9980时间大概在1.01秒左右)

select * from(select a.*,row_number() over(order by empno desc) rk from scott.emp a ) where rk<10 and rk>=1;

结果:

--rownum分页(一万条数据,查询10000至9980时间大概在0.01秒左右)

select * from(select t.*,rownum rn from(select * from scott.emp order by empno desc)t where rownum<10) where rn>=1;

select * from(select a.*,rownum rn from (select * from scott.emp) a where rownum<=10) where rn>=5 ;

--left outer join:左连接

select a.*,b.* from scott.emp a left outer join scott.dept b on a.deptno=b.deptno ;

--right outer join:右连接

select a.*,b.* from scott.emp a right outer join scott.dept b on a.deptno=b.deptno ;

--inner join

select a.*,b.* from scott.emp a inner  join scott.dept b on a.deptno=b.deptno ;

--full join

select a.*,b.* from scott.emp a full join scott.dept b on a.deptno=b.deptno ;

select a.*,b.* from scott.emp a,scott.dept b where a.deptno(+)=b.deptno ;

select distinct ename,sal from scott.emp a group by sal having ;

select * from scott.dept ;

select * from scott.emp ;

--case when then end (交叉报表)

select ename,sal,case deptno when 10 then '会计部' when 20 then '研究部' when 30 then '销售部' else '其他部门' end 部门 from scott.emp ;

结果:

select ename,sal,case when sal>0 and sal<1500 then '一级工资' when sal>=1500 and sal<3000 then '二级工资' when sal>=3000 and sal<4500 then '三级工资' else '四级工资' end 工资等级 from scott.emp order by sal desc ;

结果:

--交叉报表是使用分组函数与case结构一起实现

select 姓名,sum(case 课程 when '数学' then 分数 end)数学,sum(case 课程 when '历史' then 分数 end)历史 from 学生 group by 姓名 ;

--decode 函数

select 姓名,sum(decode(课程,'数学',分数,null))数学,sum(decode(课程,'语文',分数,null))语文,sum(decode(课程,'历史','分数',null))历史 from 学生 group by 姓名 ;

--level。。。。connect by(层次查询)

select level,emp.* from scott.emp connect by prior empno = mgr order by level ;

结果:

--sys_connect_by_path函数

select ename,sys_connect_by_path(ename,'/') from scott.emp start with mgr is null connect by prior empno=mgr ;

结果:

--start with connect by prior 语法

select lpad(ename,3*(level),'')姓名,lpad(ename,3*(level),'')姓名 from scott.emp where job<>'CLERK' start with mgr is null connect by prior mgr = empno ;

--level与prior关键字

select level,emp.* from scott.emp start with ename='SCOTT' connect by prior empno=mgr;

select level,emp.* from scott.emp start with ename='SCOTT' connect by empno = prior mgr ;

结果:

分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • oracle查看执行最慢与查询次数最多的sql语句
  • Oracle之SQL语句性能优化(34条优化方法)
  • 查询Oracle中正在执行和执行过的SQL语句
  • Oracle中死事务的检查语句
  • Oracle中简单查询、限定查询、数据排序SQL语句范例和详细注解
  • oracle中得到一条SQL语句的执行时间的两种方式
  • oracle常用sql查询语句部分集合(图文)
  • oracle导出sql语句的结果集和保存执行的sql语句(深入分析)
  • Oracle中SQL语句连接字符串的符号使用介绍
  • Oracle 查看表空间的大小及使用情况sql语句

相关文章

  • 2017-05-11Windows 64位下装安装Oracle 11g,PLSQL Developer的配置问题,数据库显示空白的完美解决方案(图文教程)
  • 2017-05-11oracle自动清理archivelog文件的具体方法
  • 2017-05-11CentOS命令行下装oracle 12c的方法(命令行模式安装)
  • 2017-05-11oracle初始化参数设置
  • 2017-05-11Oracle9i数据库异常关闭后的启动
  • 2017-05-11Oracle教程 误添加数据文件删除方法
  • 2017-05-11浅析Oracle中char和varchar2的区别
  • 2017-05-11Oracle与Mysql主键、索引及分页的区别小结
  • 2017-05-11oracle密码过期的彻底解决方案
  • 2017-05-11Linux中Oracle启动侦听报错TNS:permission denied的解决方法

文章分类

  • MsSql
  • Mysql
  • oracle
  • MariaDB
  • DB2
  • SQLite
  • PostgreSQL
  • MongoDB
  • Redis
  • Access
  • 数据库其它
  • sybase
  • HBase

最近更新的内容

    • 如何实现只授予用户查看存储过程定义的权限
    • ORACLE 12C PDB 维护基础知识介绍
    • oracle下实现恢复一个丢失的数据文件的代码
    • Oracle数据库中对null值的排序及mull与空字符串的区别
    • oracle dba 应该熟悉的命令
    • 常用Oracle分析函数大全
    • oracle—SQL技巧之(二)WMSYS.WM_CONCAT函数实现多行记录用逗号拼接在一起
    • Oracle表空间查看sql使用情况
    • oracle里IW和WW 区别
    • Oracle 获取上周一到周末日期的查询sql语句

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有