oracle 一行转多行

SELECT substr(PBTYPE, instr(PBTYPE, ',', 1, levels.lvl) + 1, instr(PBTYPE, ',', 1, levels.lvl + 1) -(instr(PBTYPE, ',', 1, levels.lvl) + 1)) as PBTYPE
    FROM
    (SELECT ',' || PBTYPE || ',' AS PBTYPE,length(PBTYPE) - nvl(length(REPLACE(PBTYPE, ',')), 0) + 1 AS cnt FROM PM_PRODUCT_CHANNEL WHERE PRODUCT_CODE=#{productCode}) a,
    (SELECT rownum AS lvl FROM (SELECT MAX(length(PBTYPE || ',') - nvl(length(REPLACE(PBTYPE, ',')), 0)) max_len FROM PM_PRODUCT_CHANNEL) CONNECT BY LEVEL <= max_len) levels
    WHERE levels.lvl <= a.cnt

oracle 一行转多行_第1张图片
oracle 一行转多行_第2张图片

你可能感兴趣的:(小代码)