文章詳情頁(yè)
oracle中關(guān)于null排序的問(wèn)題
瀏覽:124日期:2023-11-20 10:00:00
問(wèn)題描述:在處理一般的數(shù)據(jù)記錄中,對(duì)于數(shù)字類(lèi)型的字段,在Oracle的排序中,默認(rèn)把null值做為大于任何數(shù)字的類(lèi)型,當(dāng)然對(duì)于varchar2類(lèi)型的字段,默認(rèn)也是該處理方式,但是客戶(hù)要求排序的過(guò)程中,需要把null的字段默認(rèn)排在前邊(從小-->大)。一般的order by xxxx,無(wú)法解決。問(wèn)題解決:方案1:可以使用復(fù)雜的使用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) aunionselect 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中可以對(duì)order by中對(duì)比較字段做設(shè)置的方式來(lái)實(shí)現(xiàn): 如:; ……order by nvl( aaa,'-1')
標(biāo)簽:
Oracle
數(shù)據(jù)庫(kù)
排行榜
