现有一表如下(select * from mytable):
id          code           info
1           45,12          book,pc
2           22,10          paper,bike现在希望使用一条SQL拆分其中两个字段,变成如下:
id          code1     code2       info1         info2
1           45         12          book          pc
2           22         10          paper        bike
请指教。

解决方案 »

  1.   

    可以用instr和substr函数截取这两个字段实现你要的结果。
      

  2.   

    for example:
    SELECT 
    SubStr('45,12',1,InStr('45,12',',')-1)code1,
    SubStr('45,12',InStr('45,12',',')+1,Length('45,12'))code2 
    FROM dual;output:
    CODE1 CODE2
    45 12
      

  3.   

    只适用于只有1个逗号,多个逗号改函数里面的参数,怎么改请百度select id,regexp_substr(code,'[[:digit:]]+',1,1) code1,regexp_substr(code,'[[:digit:]]+',1,2) code2,regexp_substr(info,'[[:alpha:]]+',1,1) info1,regexp_substr(info,'[[:alpha:]]+',1,2) info2 from mytable