Professional Documents
Culture Documents
Input:
Lookup:
CODE MEANING
100 APPLE
101 ORANGE
102 PEARS
Output:
select inp.*,
(
select listagg(lok.meaning, ';') within group (order by 1)
from
(
select
regexp_substr(inp.attr2,'[^,]+', 1, level) as the_values
from dual
connect by level <= regexp_count(inp.attr2, ',')
) inp, lookup lok
where inp.the_values = lok.code
) as decoded_value1
from input inp;
---------------------------------------------------------------
Cheers,
select inp.*,
(
select listagg(lok.meaning, ';') within group (order by 1)
from
(
select
regexp_substr(inp.attr2,'[^,]+', 1, level) as the_values
from dual
connect by level <= regexp_count(inp.attr2, ',')
) inp, lookup lok
where inp.the_values = lok.code
) as decoded_value1
from input inp;
-----------------------------------------------------------------------------------
-
WITH got_meaning AS
(
SELECT u.id, u.col
, l.meaning
FROM input
UNPIVOT INCLUDE NULLS
( str
FOR col IN (attr1, attr2, attr3)
) u
LEFT JOIN lookup l ON INSTR ( u.str
, ',' || l.code || ','
) > 0
)
SELECT *
FROM got_meaning
PIVOT ( LISTAGG (meaning, ';')
WITHIN GROUP (ORDER BY meaning)
FOR col IN ( 'ATTR1' AS attr1
, 'ATTR2' AS attr2
, 'ATTR3' AS attr3
)
)
ORDER BY id
;
Output from your sample data:
ID ATTR1 ATTR2 ATTR3
---------- -------------------- -------------------- --------------------
1 APPLE ORANGE;PEARS