Unix Technical Forum

Inserting Data using a Stored Procedure

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 ...


Go Back   Unix Technical Forum > Database Server Software > DB2

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-27-2008, 07:52 AM
Jaraba
 
Posts: n/a
Default 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?

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-27-2008, 07:52 AM
Kiran Nair
 
Posts: n/a
Default Re: Inserting Data using a Stored Procedure

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-27-2008, 07:52 AM
Serge Rielau
 
Posts: n/a
Default Re: Inserting Data using a Stored Procedure

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-27-2008, 07:52 AM
tuarek
 
Posts: n/a
Default Re: Inserting Data using a Stored Procedure

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-27-2008, 07:52 AM
Serge Rielau
 
Posts: n/a
Default Re: Inserting Data using a Stored Procedure

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 06:04 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com