RSS
热门关键字:  cms  下载  模版  开源  dedecms
当前位置 :| 主页>站长学院>数据库>Oracle>

oracle中关于null排序的问题

来源:中国软件 作者:shaokun305  时间:2006-10-07 点击:
 

问题描述:
在处理一般的数据记录中,对于数字类型的字段,在oracle的排序中,默认把null值做为大于任何数字的类型,当然对于varchar2类型的字段,默认也是该处理方式,但是客户要求排序的过程中,需要把null的字段默认排在前边(从小-->大)。一般的
order by xxxx,无法解决。

问题解决:
方案1:
可以使用复杂的使用sql:

select * from
            (select a.*,rownum as my_sys_rownum from (
            select deptid,nvl(BDZNAME,' '),nvl(VOLLEVEL,'0'),ZBRL,nvl(ZBTS, '0'),
            nvl(FZR,'0'),nvl(DEPTIDDES,' '),nvl(TEL,' '),nvl(RUNSTATEDES,' '),
            nvl(ADDRESS,' '),BDZID from V_BDZ where  rownum<2000
            and ZBRL is null
            ) a
            union
            select b.*,rownum+(select count(*) from (
            select deptid,nvl(BDZNAME,' '),nvl(VOLLEVEL,'0'),ZBRL,nvl(ZBTS, '0'),
            nvl(FZR,'0'),nvl(DEPTIDDES,' '),nvl(TEL,' '),nvl(RUNSTATEDES,' '),
            nvl(ADDRESS,' '),BDZID from V_BDZ where  rownum<2000
            and ZBRL is null
            )) as my_sys_rownum from (
            select deptid,nvl(BDZNAME,' '),nvl(VOLLEVEL,'0'),ZBRL,
            nvl(ZBTS, '0'),nvl(FZR,'0'),
            nvl(DEPTIDDES,' '),nvl(TEL,' '),nvl(RUNSTATEDES,' '),
            nvl(ADDRESS,' '),BDZID from V_BDZ where  rownum<2000
            and ZBRL is not null order by ZBRL
            ) b
            )
            order by my_sys_rownum desc

方案2:
可以利用oracle中可以对order by中对比较字段做设置的方式来实现:
  如:  ……order by nvl( aaa,'-1')

最新评论共有 0 位网友发表了评论
发表评论
评论内容:不能超过250字,需审核,请自觉遵守互联网相关政策法规。
用户名: 密码:
匿名?
注册
栏目列表