Oracle 11g中的选择查询是什么?
Input Table
------------------
Feed_id User_Id
CL300 K111222;K555444;M123123
Required Output
--------------------------
Feed_id User_Id
CL300 K111222
CL300 K555444
CL300 M123123
答案 0 :(得分:1)
以这种方式尝试:
Oracle 11g R2架构设置:
var input = document.getElementById('inputUser').value;
var length = StringLength(input);
查询1 :
CREATE TABLE t
("Feed_id" varchar2(5), "User_Id" varchar2(23))
;
INSERT ALL
INTO t ("Feed_id", "User_Id")
VALUES ('CL300', 'K111222;K555444;M123123')
SELECT * FROM dual
;
Results :
select
"Feed_id",
trim(regexp_substr("User_Id", '[^;]+', 1, levels.column_value)) as User_Id
from
t,
table(cast(multiset(select level from dual connect by level <= length (regexp_replace("User_Id", '[^;]+')) + 1) as sys.OdciNumberList)) levels
答案 1 :(得分:0)
WITH input_table AS
(
SELECT 'CL300' AS feed_id,
'K111222;K555444;M123123' AS user_id
FROM dual
)
SELECT feed_id,
REGEXP_SUBSTR(REPLACE(REPLACE(user_id, ';;', '; ;'),';;','; ;'), '[^;]+', 1, LEVEL) AS user_id
FROM input_table
CONNECT BY
REGEXP_SUBSTR(REPLACE(REPLACE(user_id, ';;', '; ;'),';;','; ;'), '[^;]+', 1, LEVEL) IS NOT NULL