例: C15-0812-13-3 长度不固定,求各横杠之间的各子字符串 

解决方案 »

  1.   

    用個while  用instr 逐個來取
      

  2.   

    使用正则表达式:
    select regexp_substr('C15-0812-13-3','[[:alnum:]]{1,}-',1,1,'i') from dual;
    select regexp_substr('C15-0812-13-3','[[:alnum:]]{1,}-',1,2,'i') from dual;
    select regexp_substr('C15-0812-13-3','[[:alnum:]]{1,}-',1,3,'i') from dual;
      

  3.   

    问题14:
    http://topic.csdn.net/u/20081002/00/f8d90ba2-e2bb-412a-a0c5-1b6d518fc22a.html
      

  4.   

    我收藏的这段代码,赚了不少分的说。with t1 as (
    select 'C15-0812-13-3' label
      from dual
    )
    select *
      from
    (
    select trim(substr(label 
      ,instr(label, '-', 1, rn) + 1
         ,instr(label, '-', 1, rn + 1) - instr(label, '-', 1, rn) - 1
        )
       ) label
      from
    (
    --笛卡尔积
    select '-' || t1.label || '-' as label, x.rn
      from t1, (
       --这里构成一个序列
    select rownum rn
      from (
       select max(length(label) - length(replace(label, '-'))) + 2 comma_cnt --"-"的数量
         from t1
          )
       connect by rownum <= comma_cnt
       ) x
    )

     where label is not null
      

  5.   

    哈哈,压箱底的货?
    那不客气了,收下呵呵.
    其实mantisXF总结了很多,他那个帖子没被推荐帖,真不知道这些版主怎么当的.