Hi,
Oracle Gurus!
I have a requirement for a SQL solution and only a SQL Solution or the approach listed below is even Possible, or if any one can give me a Better Solution
Lets Say I have a Scenario
Where in I Have a Query with Comma separated List as Data using LISTAGG() Function.
Now I have a Select query with a Comma Separated list as output, And These Comma Separated Lists are defined as Column names in another Table(say Table name form_item_nm),
the Task is to write a Query which will Pass this Comma separated Values in the Query as Column names from the form_item_nm table
I have Two Tables
with Structures as
Table: ITEM_DEF_TABLE
id | Column | Val
|
---|
1 | item_name | item1 |
2 | item_name | item2 |
3 | item_name | item3 |
5 | item_name | item4 |
| | |
Table: FORM_ITEM_NM
id | item1 | item2 | item3 | item4 |
---|
1 | ABC1 | DEF1 | XYZ1 | ABB1 |
2 | ABC2 | DEF2 | XYZ2 | ABB2 |
3 | ABC3 | DEF3 | XYZ3 | ABB3 |
4 | ABC4 | DEF4 | XYZ4 | ABB4 |
| | | | |
Please find the Example
Query1:
SELECT LISTAGG(item_name,',') WITHIN GROUP (ORDER BY itme_name) item_name_list
FROM item_def_table
The Output is (item1,item2,item3,item4)
THEN
QUERY 2
SELECT
(SELECT LISTAGG(item_name,',') WITHIN GROUP (ORDER BY itme_name) item_name_list
FROM item_def_table)
FROM form_item_nm;
But Unfortunately I am getting only Result set as the Same List returened with Number of Rows in my form_item_nm table
i.e
Lets Say I got 4 Rows in my form_item_nm I am getting the Result of my Query2 is like this below
SELECT (SELECT LISTAGG(item_name,',') WITHIN GROUP (ORDER BY itme_name) item_name_list FROM item_def_table) FROM form_item_nm; |
---|
item1,item2,item3,item4 |
item1,item2,item3,item4 |
item1,item2,item3,item4 |
item1,item2,item3,item4 |
item1,item2,item3,item4 |
|
Thanks