Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

PL/SQL - How to execute queries generated within a query?

Jasper TanglibApr 4 2021 — edited Apr 4 2021

Hi,
I have this code in Oracle Apex that generates multiple queries.
generate_queries.pngI want to execute the Insert queries generated as seen in the above screenshot. Now my code looks like this. please refer to code below.
DECLARE
l_insert varchar2(4000);
BEGIN
l_insert := q'{
WITH cols as (
SELECT drv.table_name,
(SELECT listagg(column_name,',') WITHIN GROUP (ORDER BY column_id)
FROM user_tab_cols
where table_name = drv.table_name
) column_list
FROM user_tables drv
where table_name like 'XT%'
) select q'[insert into ALL_PORT_OBJS (loadid,xtid,xt,name) SELECT 150 , 'xtid' , 'xt_xml', name FROM xt_xml]' metasql from cols}';
EXECUTE IMMEDIATE l_insert;
END;
This returns Statement processed but it actually did not execute the insert statements.
I think there is something else I need to do in the "select q'[insert into..." section?
Please help I am stucked on this. Any idea or suggestion is appreciated.

-Jazz

Comments

Post Details

Added on Apr 4 2021
7 comments
2,193 views