我有字符串如何在pl / sql中使用split?

时间:2015-06-22 06:55:43

标签: oracle oracle-sqldeveloper

我有字符串字符,我应该用逗号分隔这个字符串

任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

SQL Fiddle

Oracle 11g R2架构设置

CREATE TABLE data ( id, str ) AS 
SELECT 1, '1,2,3,4,5' FROM DUAL
UNION ALL SELECT 2, 'One,Two,Three' FROM DUAL
UNION ALL SELECT 3, 'AA,BB,CC,DD,,EE' FROM DUAL;

查询1

SELECT  ID,
        REGEXP_SUBSTR( d.str, '[^,]+', 1, l.COLUMN_VALUE ) AS value,
        l.COLUMN_VALUE AS "index"
FROM    data d,
        TABLE(
          CAST(
            MULTISET(
              SELECT LEVEL
              FROM   DUAL
              CONNECT BY  LEVEL <= REGEXP_COUNT( d.str, '[^,]+')
            ) AS sys.OdciNumberList
          )
        ) l
ORDER BY
       1,3

<强> Results

| ID | VALUE | index |
|----|-------|-------|
|  1 |     1 |     1 |
|  1 |     2 |     2 |
|  1 |     3 |     3 |
|  1 |     4 |     4 |
|  1 |     5 |     5 |
|  2 |   One |     1 |
|  2 |   Two |     2 |
|  2 | Three |     3 |
|  3 |    AA |     1 |
|  3 |    BB |     2 |
|  3 |    CC |     3 |
|  3 |    DD |     4 |
|  3 |    EE |     5 |