我想把  
       a,b,c;d,e,f;g,h,i;格式的字符串在ORACLE中分割成       a b c 
       d e f
       g h i
    的格式。
我在想用split分割,但不知道oracle中如何使用此函数,请各位大侠帮忙。

解决方案 »

  1.   


    --10g以上的话使用正则表达式
    SQL> with t as(
      2       select 'a,b,c;d,e,f;g,h,i;' txt from dual)
      3  select replace(regexp_substr(txt,'[^;]+',1,level),',',' ') txt
      4  from t
      5  connect by
      6          level<=length(txt)-length(replace(txt,';',''))+1
      7  /
     
    TXT
    ------------------------------------
    a b c
    d e f
    g h i
      

  2.   

    --来个9i-10g都可用的
    WITH t AS
     (SELECT 'a,b,c;d,e,f;g,h,i;' s FROM dual)
    SELECT substr(s,
                  instr(s, ';', 1, LEVEL) + 1,
                  instr(s, ';', 1, LEVEL + 1) - instr(s, ';', 1, LEVEL) - 1)
      FROM (SELECT ';' || s s FROM t)
    CONNECT BY LEVEL < length(s) - length(REPLACE(s, ';'));