select '哈哈' a from dual
union 
select '嘿嘿' a from dual
union
select '嘻嘻' a from dual
上表 我想按照 嘿嘿-嘻嘻-哈哈 这样的顺序排序表中记录 如何排
oracle中有没有类似sql中的charindex这样的函数可以在order by的后面按固定数据排序

解决方案 »

  1.   

    可以decode一下.charindex不了解.
      

  2.   

    SQL> with t as (select '哈哈' a from dual
      2  union
      3  select '嘿嘿' a from dual
      4  union
      5  select '嘻嘻' a from dual)
      6  select * from t order by decode(a,'哈哈','中',a);
     
    A
    ----
    嘿嘿
    嘻嘻
    哈哈
     
      

  3.   


    select * from t order by decode(a,'哈哈','中',a) desc;
      

  4.   


    --charindex 也是根据某个字符串在串字符串来找出其位置来排序的
    SQL> edi
    已写入 file afiedt.buf  1  with tmp
      2  as
      3  (select '哈哈' a from dual
      4  union
      5  select '嘿嘿' a from dual
      6  union
      7  select '嘻嘻' a from dual)
      8* select a from tmp order by decode(a,'嘿嘿',0,1)
    SQL> /A
    ----
    嘿嘿
    嘻嘻
    哈哈
      

  5.   


    您按照什么来加ID呢?你不是的先排完序再加ID么?那样的话加ID还有啥意义?
      

  6.   

    知道怎么弄了 wkc168 启发了我