4

在 Oracle 中,我有名为 orderids 的列

orderids
111,222,333
444,55,66
77,77

如何获得输出为

Orderid
111
222
333
444
55
66
77
77
4

4 回答 4

4

试试这个:

 WITH TT AS
 (SELECT orderid COL1 FROM orders)
 SELECT substr(str,
                   instr(str, ',', 1, LEVEL) + 1,
                   instr(str, ',', 1, LEVEL + 1) -
                   instr(str, ',', 1, LEVEL) - 1) COL1
     FROM   (SELECT rownum AS r,
                    ','|| COL1||',' AS STR
               FROM   TT )
     CONNECT BY PRIOR r = r
         AND    instr(str, ',', 1, LEVEL + 1) > 0
         AND    PRIOR dbms_random.STRING('p', 10) IS NOT NULL
;

在此处输入图像描述

看到这个SQLFiddle

于 2013-10-05T08:45:53.363 回答
1

这是一种方法:

with order_table as (
  select '111,222,333' as orderids from dual
  union all select '444,55,66' from dual
  union all select '77,77' from dual
)
select substr(orderids, instr(orderids, ',', 1, lvl) + 1, instr(orderids, ',', 1, lvl + 1) - instr(orderids, ',', 1, lvl) - 1) orderid 
from
  ( select ',' || orderids || ',' as orderids from order_table ),
  ( select level as lvl from dual connect by level <= 100 )
where lvl <= length(orderids) - length(replace(orderids, ',')) - 1;

只需删除 WITH 子句并order_table用您的真实表替换。

于 2013-10-05T09:35:39.153 回答
0

这也可能对你有所帮助,

with t(orderid) as 
(
SELECT '111,222,333' FROM dual
UNION
SELECT '444,55,66' FROM dual
UNION
SELECT '177,77' FROM dual
)
SELECT trim(x.COLUMN_VALUE.EXTRACT('e/text()')) cols 
FROM t t, TABLE (xmlsequence(XMLTYPE('<e><e>' || REPLACE(t.orderid,',','</e><e>')|| '</e></e>').EXTRACT('e/e'))) x;
于 2013-10-05T09:38:59.303 回答
0
instr(','||NVL('972414AQ,972414AQ',I.CUSIP)||',', ','||I.CUSIP||',') > 0

这是我正在寻找的实际查询。

于 2016-10-05T18:43:19.203 回答