I have a table in oracle with 10 columns, say Table A with col_1, col_2, col_3 etc. I have another table, Table B with rows that has column names from table A co1_1, col_2, col_3. The rows in Table B can vary.
TABLE A
COL1 COL2 COL3 COL4 COL5 COL6 COL7 COL8 COL9 COL10
TABLE B
COL1
COL2
COL3
I want to write an oracle sql query which dynamically gets the select columns names based on the column names(rows) in table B.
If table B has 3 rows with corresponding column names then my query should look like this
select col_1, col_2, col_3 from A
If table B has 4 rows then my query should dynamically change to below
select col_1, col_2, col_3, col_4 from A