select t.code, t.name, t.equalcode 
from DW_2010_T_FMTERM t 
where t.code>=1 and t.code<=12 and equalcode is null 
order by t.code语句如上,如果运行的部分不加order by,那么结果为 1,2,3,4,5,6,7,8,9,10,11,12如果加上order by code,反而成了。。1,10,11,12,,2,3,4,5,6,7,8,9这是为什么呢?

解决方案 »

  1.   

    因为你的code是字符型的
    select t.code, t.name, t.equalcode  
    from DW_2010_T_FMTERM t  
    where t.code>=1 and t.code<=12 and equalcode is null  
    order by to_number(t.code)
      

  2.   

    有这回事?
    order by to_number(t.code) 
      

  3.   

    楼主,你得t.code是字符类型吧如果加上order by code,反而成了。。1,10,11,12,,2,3,4,5,6,7,8,9这个明显是字符类型排序;加上order by to_number(t.code)  ,就是转换成数字了;
    结果当然就是:
    1,2,3,4,5,6,7,8,9,10,11,12
      

  4.   

    --用to_number将字符转换为数字
    order by to_number(t.code)