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!

SQL query as a variable in a for-loop

LauryMay 2 2021 — edited May 2 2021

Hi,
I have a PL/SQL block like this:
set serveroutput on
declare
t_rc sys_refcursor;
v_sql varchar2(2000);
begin
---
v_sql := q'{
select
t.id as id,
(t.id || ':' || t.customer) as customer
from
(
select
rownum as id,
(customer_id || ':' || cust_first_name || ':' || cust_last_name) as customer
from
customers
) t
}';
---
open t_rc for v_sql;
for c in v_sql
loop
<... do something with each row and insert ...>
end loop;
---
end;
/

This piece of code is not the correct syntax.
Does someone know how to build such a for-loop, with a "variable" SQL text in v_sql?

Kind Regards

This post has been answered by Solomon Yakobson on May 2 2021
Jump to Answer
Comments
Post Details
Added on May 2 2021
2 comments
4,686 views