0

I have code_table which contain the below columns:

- ID
- FIELD_NAME
- TABLE_NAME
- WHERE_CONDITION

now, I need to write select statement that return table contain 2 columns, the first column is code_table.ID, and the other column is the result of the below select statement

select code_table.FIELD_NAME 
from code_table.TABLE_NAME 
where code_table.WHERE_CONDITION = 1;

how can I solve it ?

Juan Carlos Oropeza
  • 47,252
  • 12
  • 78
  • 118
user7157121
  • 57
  • 1
  • 5

1 Answers1

0

Try this using anonymous block. Hope this helps

DECLARE
    cursor cur_code_tab is
    select id,field_name,table_name,where_condition from code_table;
    sql_query varchar2(500);
BEGIN
    for i in cur_code_tab loop
        sql_query:='select '''||i.id||''','||i.field_name||' from '||i.table_name||' where '||i.where_condition=1;
        execute immediate(sql_query);
    end loop;
END;
EhsanT
  • 2,077
  • 3
  • 27
  • 31
Himanshu
  • 91
  • 7