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.

Dynamic sql in oracle objects

VPrasadDec 12 2024 — edited Dec 12 2024

create or replace TYPE m1 force AS OBJECT
(tno number, tname varchar2(10));

create or replace TYPE m1_tt
AS TABLE OF m1;

create table test (tno number, tname varchar2(10));

declare
a number:= 1;
b varchar2(10):= 1;
ty m1_tt;
tem varchar2(100) := 'ty(i).tno, ty(i).tname';
begin
ty := m1_tt();
ty.extend;
ty(1) := m1(10,10);
for i in 1 .. ty.count loop

   execute immediate 'insert into test values('||ty(i).tno||','|| ty(i).tname||')';  

end loop;
end;

the above piece of code is working.

But, collection variables can be limited, i mean, the table columns can be limited, less or more.
i need to frame the dynamic sql based on the list of collection variables.

collection variables can be vary. more or less.

Example:

execute immediate 'insert into test values(ty(i).tno, ty(i).tname)'

or

execute immediate 'insert into test values(:1, :2)' using ‘ty(i).tno, ty(i).tname’

Any suggestions please..

This post has been answered by James Su on Dec 12 2024
Jump to Answer

Comments

Processing

Post Details

Added on Dec 12 2024
17 comments
253 views