Oracle排序不遵循规则

时间:2013-08-08 21:19:57

标签: oracle decode

我有以下订单,我希望以ROID顺序输出。相反,输出以OIDR顺序显示。为什么R会在最后而不是在开始?

select narritive_section as ns, decode(narritive_section,'R','Origin','O','Initial Observation','I','Investigation','D','Disposition') as narritive_section 
    ,person_id, offense_id, entry_date, narritive_text, c_narritive_text  
from t_narritive 
where not narritive_text is null and offense_id =  11514
order by offense_id, decode(
    narritive_section, 'R',1, 'O',2, 'I',3, 'D',4);

1 个答案:

答案 0 :(得分:1)

您拥有的Attack_id具有更高的排序优先级,然后是ROID排序。按顺序切换两个参数可以解决您的问题。

select narritive_section as ns, decode(narritive_section,'R','Origin','O','Initial Observation','I','Investigation','D','Disposition') as narritive_section, person_id, offense_id, entry_date, narritive_text, c_narritive_text
from t_narritive
where not narritive_text is null and offense_id = 11514
order by decode(narritive_section, 'R',1, 'O',2, 'I',3, 'D',4), offense_id;