This is a discussion on Inserting Data using a Stored Procedure within the DB2 forums, part of the Database Server Software category; --> In Microsoft SQL I can run the following command: insert into table execute proc1 to insert data into a ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| |||
| I am not sure if we can directly call the procedure and insert its result set into a table in a single statement. Another way out is to to write a stored procedure for doing the same ..You can associate a cursor with stored procedure result set and hence fetch the data from the stored procedure result which can be inserted into the table . You can use ASSOCIATE RESULT SET LOCATORS and ASSOCIATE CURSOR for the same . Regards, Kiran Nair |
| |||
| Jaraba wrote: > In Microsoft SQL I can run the following command: > > insert into table execute proc1 > > to insert data into a table. > > Is there a comparable way to do this in DB2? > DB2 distinguishes between functions and procedures. INSERT INTO table SELECT * FROM TABLE(foo1(..)) AS F Would be the equivalent. That would be a table-functions (you have them in SQL Server as well). You can also use scalar function if all you have is one return value. Cheers Serge -- Serge Rielau DB2 Solutions Development IBM Toronto Lab |
| |||
| Serge, Please correct me if I'm wrong. To invoke a SP, we have to issue a "CALL" . Even if the SP returns a result set, we wouldn't be able to use its output in a SQL statement because "CALL" cannot be implicity issued from a sql statement. Regards Mehmet |
| ||||
| tuarek wrote: > Serge, > > Please correct me if I'm wrong. > > To invoke a SP, we have to issue a "CALL" . Even if the SP returns a > result set, we wouldn't be able to use its output in a SQL statement > because "CALL" cannot be implicity issued from a sql statement. Correct. If the procedure is "given" then you will need to process the result set row by row using row inserts. Cheers Serge -- Serge Rielau DB2 Solutions Development IBM Toronto Lab |
| Thread Tools | |
| Display Modes | |
|
|