oracle中对排序的总结Oracle认证考试
文章作者 100test 发表时间 2009:12:11 18:09:59
来源 100Test.Com百考试题网
"tbbnc">
-- 按拼音排序 (系统默认)
0select * from perexl order by nlssort(danwei, NLS_SORT=SCHINESE_PINYIN_M ).
-- 按部首排序
0select * from perexl order by nlssort(danwei, NLS_SORT=SCHINESE_STROKE_M ).
-- 按笔画排序
0select * from perexl order by nlssort(danwei, NLS_SORT=SCHINESE_RADICAL_M ).
--排序后获取第一行数据
0select * from (0select * from perexl order by nlssort(danwei, NLS_SORT=SCHINESE_PINYIN_M ) )C where rownum=1
--降序排序
0select * from perexl order by zongrshu desc
--升序排序
0select * from perexl order by zongrshu asc
--将nulls始终放在最前
0select * from perexl order by danwei nulls first
--将nulls始终放在最后
0select * from perexl order by danwei desc nulls last
--decode函数比nvl函数更强大,同样它也可以将输入参数为空时转换为一特定值
0select * from perexl order by decode(danwei,null, 单位是空 , danwei)
-- 标准的rownum分页查询使用方法
0select *from (0select c.*, rownum rn from personnel c)where rn >.= 1and rn <.= 5
--在oracle语句rownum对排序分页的解决方案
--但是如果, 加上order by 姓名 排序则数据显示不正确
0select *from (0select c.*, rownum rn from personnel c order by 出生年月)where rn >.= 1and rn <.= 5
--解决方法,再加一层查询,则可以解决
0select *from (0select rownum rn, t.*from (0select 姓名, 出生年月 from personnel order by 出生年月 desc) t)where rn >.= 1and rn <.= 5
--如果要考虑到效率的问题,上面的还可以优化成(主要两者区别)
0select *from (0select rownum rn, t.*from (0select 姓名,出生年月 from personnel order by 出生年月 desc) t where rownum <.= 10) where rn >.= 3
--nvl函数可以将输入参数为空时转换为一特定值,下面就是当单位为空的时候转换成“单位是空”
0select * from perexl order by nvl(danwei, 单位是空 )