If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Multiple assign

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-21-04, 09:41
b_moni b_moni is offline
Registered User
 
Join Date: Aug 2003
Posts: 16
Multiple assign

How to assign values to more variables in a single statement?

I have a function which returns a table (actually a row from a table from the given primary key).
How to assign the columns returned by the function to more variables within a single statement?

I have the function: f(id int) returns table(col1, col2...coln).....
I want to call this function from a trigger:
???? = (select t.* from table(f(1)) as t)

What should I put instead of "????"
Should I use a structure? How?
Should I use a row function instead a table function?

I don't want to have the following code (although this code works):
declare a_col1...;
declare a_col2...;
set a_col1 = (select t.col1 from table(f(1)) as t); ......
set a_col2 = (select t.col2 from table(f(1)) as t); ......

Can anyone help?
Reply With Quote
  #2 (permalink)  
Old 06-21-04, 09:50
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
You do not state version od DB2 or which OS.

In 8.1 for LUW, you can:

SET (v1,v2,v3,...) = myfunction(pk)

HTH

Andy
Reply With Quote
  #3 (permalink)  
Old 06-21-04, 11:09
b_moni b_moni is offline
Registered User
 
Join Date: Aug 2003
Posts: 16
Sorry, I've forgot to mention:

Database server = DB2/LINUX 7.2.0
Reply With Quote
  #4 (permalink)  
Old 06-22-04, 08:11
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Check the DB2 7.2 SQL Reference manual to see if you can use SET Variable the same way as in 8.1. (I cannot remember if you can or not).

Andy
Reply With Quote
  #5 (permalink)  
Old 06-22-04, 09:16
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
You can do

SELECT col1,col2 into v1,v2 from table1
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
  #6 (permalink)  
Old 06-22-04, 10:22
b_moni b_moni is offline
Registered User
 
Join Date: Aug 2003
Posts: 16
select c1,c2 into v1,v2 from.... doesn't work in trigger.

But: set(v1,v2) = (select c1,c2 from ....) works!.

I tested with 7.2.0 on Linux (although I didn't find SET(...) in DB2 documentation, which I consider a true nightmare).

Thank you very much for help!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On