469,271 Members | 1,381 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,271 developers. It's quick & easy.

Inserting Data using a Stored Procedure

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?

Apr 26 '06 #1
4 4462
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

Apr 26 '06 #2
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
Apr 26 '06 #3
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

Apr 26 '06 #4
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
Apr 26 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by hooterbite | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.