搜索到的ZZZH的字段如上,包含了空字段,并且甲乙丙丁不以顺序排序,反复测试了多次得到正确sql写法,现记下
方法一:使用case .. when..
select zzzh from proj_case01 where zzzh is not null order by ( case substr(zzzh,1) when N'甲' then 1 when N'乙' then 2 when N'丙' then 3 when N'丁' then 4 else 5 end ) ;
方法二:使用Oracle特有的decode
select zzzh from proj_case01 where zzzh is not null order by decode(substr(zzzh,1),N'甲',1,N'乙',2,N'丙',3,N'丁',4);
在字符串前加上N,目的是转换为Unicode,否则会提示:ORA-12704:character set mismatch错误,或者得不到正确结果
原文链接:https://www.f2er.com/oracle/213774.html