Question : changes direct inserts to APIs

Hi

I am looking at oracle package in 11g rel2 that has the cursor and several insert statements based on value of cursor I want to modularize this code to insert APIs - calling insert procedurs for each of the insert operations. Is it just replacing the inserts with a procedure but the values to insert are coming from cursor, is the scope of the value also seen outside the procedure in which cursor is created. Is it good to pass the same cursor value to 2 different insert procedures?

procedure main_procedure (input1 value..output value..)
is
cursor main_cursor is
select <all columns>
from table
whre.. joining condiitons

insert into table1 values (main_cursor.value1,...)

insert into table2 values (main_cursor.value1..)

Thanks!!

Answer : changes direct inserts to APIs

By API, I assumed masking the call with other PL/SQL procedures.

>>but not sure how I can do that since the cursor value that is needed for insert is only available to

Look at the pseudo code I posted.  You pass the cursor values into the stored procedure.

>>and how is it possible to publish this APIs so other applications can use this API?

If you have the procedure declared in the package, it is exposed. to anything that can call that package.

I think where you are going to run into trouble is the procedure would have to account for EVERY column in the table because different 'cursors' from different apps might pass in different values.

For example:
give the table:
create table tab1(col1 char(1), col2 char(1), col3 char(1));

proc1 might have a cursor
select 'a' a,'b' b from dual;

and an insert like:
insert into tab1(col1, col2) values (cur.a, cur.b);


proc2 might have a cursor
select 'a' a,'c' c from dual;

and an insert like:
insert into tab1(col1, col3) values (cur.a, cur.c);

notice both didn't insert into ALL columns in tab1.  Your insert proc would need to account for ALL three columns as input parameters.

then that happens if someone adds a column to the table?
Random Solutions  
 
programming4us programming4us