你的位置:首页 > 软件开发 > 数据库 > oracle 排序

oracle 排序

发布时间:2015-08-13 19:00:06
1、ORDER BY 中关于NULL的处理缺省处理,Oracle在Order by 时认为null是最大值,所以如果是ASC升序则排在最后,DESC降序则排在最前。当然,你也可以使用nulls first 或者nulls last 语法来控制NULL的位置。 Nulls firs ...

1、ORDER BY 中关于NULL的处理

缺省处理,Oracle在Order by 时认为null是最大值,所以如果是ASC升序则排在最后,DESC降序则排在最前。

当然,你也可以使用nulls first 或者nulls last 语法来控制NULL的位置。 Nulls first和nulls last是Oracle Order by支持的语法 如果Order by 中指定了表达式Nulls first则表示null值的记录将排在最前(不管是asc 还是 desc) 如果Order by 中指定了表达式Nulls last则表示null值的记录将排在最后 (不管是asc 还是 desc) 使用语法如下:

--将nulls始终放在最前 select * from 表名 order by 列名 nulls first

--将nulls始终放在最后 select * from 表名 order by 列名 last

 

2、几种排序的写法 单列升序:

 

select<column_name> from <table_name> order by <column_name>; (默认升序,即使不写ASC)

单列降序:select <column_name> from <table_name> order by <column_name> desc; 

多列升序:select <column_one>, <column_two> from <table_name> order by <column_one>, <column_two>; 

多列降序:select <column_one>, <column_two> from <table_name> order by <column_one> desc, <column_two> desc; 

多列混合排序:select <column_one>, <column_two> from <table_name> order by <column_one> desc, <column_two> asc;

 

 

 

sql 无规律排序

 

select * from ( select 1 a,1 b from dual union all  select 1 a,2 b from dual  union all  select 10 a,2 b from dual  union all  select 100 a,2 b from dual ) xxx order by decode(a,100,0,a)

原标题:oracle 排序

关键词:oracle

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

可能感兴趣文章

我的浏览记录