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!

I want to loop it through data from two different table using same for loop where query is to be rep

Raj NathJul 30 2014 — edited Jul 30 2014

I have the data in two table having similar column structure, i want to loop it through the data of these two tables

based on certain condition and at run time i want to put the query in for loop, example is given, Please help me

create table ab(a number, b varchar2(20));

insert into ab

select rownum, rownum||'sample'

from dual

connect by level <=10

create table bc(a number, b varchar2(20));

insert into bc

select rownum+1, rownum+1||'sample'

from dual

connect by level <=10

declare

l_statement varchar2(2000);

bool boolean;

begin

bool := true;

if true then

l_statement:='select * from ab';

else

l_statement:='select * from bc';

end if

for iĀ  in execute immediate l_statementĀ  -- something like this but i am not sure

loop

dbms_output.put_line(i.a);

end loop;

end;

Something like this but this is not a working peace of code.

This post has been answered by RajenB on Jul 30 2014
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 27 2014
Added on Jul 30 2014
6 comments
1,143 views