Oracle 將逗號分隔的列轉行


 

 

 

需求:按ID,把PARTICIPATORS字段里的內容按‘,’ 分開,轉成行

 

select id,PARTICIPATORS from
(with test as (select id ,PARTICIPATORS  from NSC_OA_RW  where PARTICIPATORS is not null )
    select id,substr(t.cPARTICIPATORS,instr(t.cPARTICIPATORS, ',', 1, c.lv) + 1,
    instr(t.cPARTICIPATORS, ',', 1, c.lv + 1) - (instr(t.cPARTICIPATORS, ',', 1, c.lv) + 1)) AS PARTICIPATORS
  from 
    (select id,',' || PARTICIPATORS || ',' AS cPARTICIPATORS,length(PARTICIPATORS || ',') - nvl(length(REPLACE(PARTICIPATORS, ',')), 0) AS cnt FROM test) t,
    (select LEVEL lv from dual CONNECT BY LEVEL <= 100) c where c.lv <= t.cnt ) 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM