博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Oracle优化查询改写(第二章-给查询结果排序)
阅读量:7192 次
发布时间:2019-06-29

本文共 1049 字,大约阅读时间需要 3 分钟。

hot3.png

2.1以指定的次序返回查询结果

select empno,ename,hiredate from emp where deptno =10 order by hiredate

或者

select empno,ename,hiredate from emp where deptno =10 order by 3;

2.2按多个字段排序(略)

2.3按子串排序

select last_name as 名称,          phone_number as 号码,          salary as 工资,          substr(phone_number,-4) as 尾号          from hr.employees          where rownum<=5 order by 4;

2.4 TRANSLATE

select translate('ab你好bcadefg','abcdefg','1234567') AS NEW_STR from dual;

2.5按数字和字母混合字符串中的字母排序

create or replace view v     as     select empno|| '' || ename as data from emp;
select data,TRANSLATE(data,'- 0123456789','-') as ename from v order by 2;

2.6 处理空值排序

    空值在前

 

select ename,sal,comm from emp order by 3 nulls first;

    空值在后

    

select ename,sal,comm from emp order by 3 nulls last;

2.7根据条件不同列中的值来排序

    领导对工资在1000到2000元之间的员工更感兴趣,于是要求工资在这个范围的员工要排在前面,以便优先查看。

select empno as 编码,           ename as 姓名,           case when sal>=1000 and sal <2000 then 1 else 2 end as 级别,           sal as 工资     from emp where deptno =30 order by 3,4;

 

转载于:https://my.oschina.net/projerry/blog/1584216

你可能感兴趣的文章
rocketmq之源码分析broker整体事件流(十四)
查看>>
我的友情链接
查看>>
iOS面试题第一波
查看>>
在centos中安装puppet和安装过程的一些错误解决
查看>>
html元素
查看>>
使用kaptcha生成验证码
查看>>
MyBatis学习总结(五)——实现关联表查询
查看>>
Java基础学习总结(4)——对象转型
查看>>
Ubuntu 11.10不得不知的快捷键
查看>>
TCP/IP
查看>>
Maven学习总结(四)——Maven核心概念
查看>>
python 连接mongodb ,并将EXCEL文档导入mongodb
查看>>
SSH
查看>>
Spring学习总结(4)——Spring AOP教程
查看>>
Python Oracle数据库备份脚本
查看>>
<More Effective C++>笔记--技巧
查看>>
我的友情链接
查看>>
第三节 在shell脚本中进行for循环
查看>>
Java Script 中定义对象的几种方式
查看>>
mysql编译安装完成后,启动时报错The server quit without updating PID file
查看>>