By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,924 Members | 1,727 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,924 IT Pros & Developers. It's quick & easy.

Inserting Data using a Stored Procedure

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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.