Help Needed - For Creating Generic Procedure for Insert/Update/Delete-Urgnt
501777Jun 14 2007 — edited Jun 15 2007Hi
I have 20 tables like EMP,DEPT but my objective is to create the generic procedure for Insertion and Updation and Deletion..
1) INSERTION: I will pass any one of the table recordset as input to the procedure that will inesrt the record to the concern tables :
eg:
procedure insert(rs in sys_refcursor,tname in varchar2) is
--****** How to declare the genric cursor for all table record sets******
Type rec is table of rs%rowtype index by binary_integer; ??????
rec1 rec;
begin
fetch rs bulk collect into rec1;
for i in rec1.first..rec1.last
loop
'Execute immediate insert into '||tname|| 'values '||rec1(i);
end loop;
exception
when others then
null;
end;
Help Needed:
~~~~~~~~~~
For insertion How to create the generic procedure like the above as to avoid the redundancy for 20 to 30 tables.....????
2) Updation :
========
1)How to create the generic procedure for updation..
2) How to include the primary key columns in the where clause of the update statement regardless of the table like the below statement
Update emp set row=rec1(i)
where eno=rec1(i).eno;
procedure update(rs in sys_refcursor,tname in varchar2) is
--****** How to declare the genric cursor for all table record sets******
Type rec is table of rs%rowtype index by binary_integer; ??????
rec1 rec;
begin
fetch rs bulk collect into rec1;
for i in rec1.first..rec1.last
loop
'Execute immediate update '||tname|| 'values '||rec1(i);?????????
end loop;
exception
when others then
null;
end;
3) DELETE:
==========
1)How to create the generic procedure for DELETION
2) How to include the primary key columns in the where clause of the delete statement regardless of the table like the below statement
delere from emp where eno=rec1(i).eno;
The reason for creating generic procedure is i will pass the record set for any table but the operation is same meaning insertion/updation /deletion.. for example.
declare
rc is sys_Refcursor;
begin
open rc for select * from emp;
insert(rc,'EMP');
end;
So please suggest How should i implement this logic efficiently in OLTP system by ORACLE 9i and tell me the WORK AROUND if not possible......
Thanks in advance....