I'm trying to use the SQL queries stored in a table, in a insert statement inside the procedure.
Below is the statement_table,
STMT_ID STATMENT1 STATEMENT2
S001 INSERT INTO TABLE1 (S_ID, REQUEST_NUM,CASE_ID,C1,C2) select min(s_id) s_id, REQUEST_NUM, CASE_ID, trim(c1),
ABS(max(case when source = 'S1' then c2 end) +
max(case when source = 'S2' then -c2 end))
from TABLE2 where REQUEST_NUM =REQUEST_IN
group by REQUEST_NUM , CASE_ID, trim(c1)
order by S_ID
Below is the procedure block,
execute immediate 'select '||STATEMENT1||'+'||STATEMENT2||' FROM statement_table where stmt_id='S001';
The result that I am trying to get is,
INSERT INTO TABLE1 (S_ID, REQUEST_NUM,CASE_ID,C1,C2)
select min(s_id) s_id, REQUEST_NUM, CASE_ID, trim(c1),
ABS(max(case when source = 'S1' then c2 end) +
max(case when source = 'S2' then -c2 end))
from TABLE2 where REQUEST_NUM =REQUEST_IN
group by REQUEST_NUM , CASE_ID, trim(c1)
order by S_ID
Please help.