FILM_ID TITLE
---------- ----------
1 Frozen,Frozen
2 Frozen,High,Low,High
FILM_ID TITLE
---------- ----------
1 Frozen
2 Frozen,High,Low
如果值为Frozen,Frozen
我需要查询才能获得冻结以及第二个值我应该Frozen,High,Low
答案 0 :(得分:0)
试试这个解决方案:
SELECT film_id, LISTAGG(title,',') WITHIN GROUP (Order BY title) TITLE
FROM
(select distinct film_id,
regexp_substr(Title,'[^,]+', 1, level) as title
from Table1
connect by regexp_substr(Title, '[^,]+', 1, level) is not null
) t
GROUP BY film_id
<强>输出:强>
FILM_ID | TITLE
--------------------------
1 | Frozen
2 | Frozen,High,Low
链接演示:
答案 1 :(得分:0)
这是一个选项:
SQL> with test (film_id, title) as
2 (select 1, 'Frozen,Frozen' from dual union
3 select 2, 'Frozen,High,Low,High' from dual
4 ),
5 inter as
6 (select distinct film_id, regexp_substr(title, '[^,]+', 1, column_value) title
7 from test,
8 table(cast(multiset(select level from dual
9 connect by level <= regexp_count(title, ',') + 1
10 ) as sys.odcinumberlist))
11 )
12 select film_id, listagg(title, ',') within group (order by title) title
13 from inter
14 group by film_id;
FILM_ID TITLE
---------- ------------------------------
1 Frozen
2 Frozen,High,Low