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 > Exception handling in User Defined Function

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-13-03, 05:48
Raj Shekhar Raj Shekhar is offline
Registered User
 
Join Date: Jun 2003
Posts: 38
Exception handling in User Defined Function

Hi All,

I am writing an User Defined function. I am trying to handle exceptions, but unable to do so. I have few queris:
1.)Is exception handling is possible in DB2 UDF.
2)If possible how can I wirte a WHEN NO DATA FOUND excption(oracle's eqivalent) in db2.
3.)Can anyone please figure out where I am missing in the following code :

CREATE FUNCTION DOM9OCT.xyz( lo_sal integer )

RETURNS INTEGER

LANGUAGE SQL

READS SQL DATA

------------------------------------------------------------------------

-- SQL UDF (Scalar)

------------------------------------------------------------------------

F1: BEGIN ATOMIC

declare l_var integer;

declare l_flag char(1);

DECLARE GENERATEQUERYEXCEPTION CONDITION FOR SQLSTATE 'OR000';

DECLARE EXIT HANDLER FOR SQLEXCEPTION, SQLWARNING

BEGIN

-- SET l_var=5;

END;

set l_flag='N';

set l_var=0;

while l_flag='N' do

Select PARENTENTITYID as l_var from umlcompositestate where compositestateid = l_var and modelid =2 and parententitytype = 121;

end while;

--end;

RETURN l_var;

END





Thanks
__________________
Raj Shekhar
Reply With Quote
  #2 (permalink)  
Old 10-13-03, 13:57
achiola achiola is offline
Registered User
 
Join Date: May 2002
Location: General Deheza, Cba, Arg.
Posts: 273
Re: Exception handling in User Defined Function

test this:

Select PARENTENTITYID into l_var from umlcompositestate where compositestateid = l_var and modelid =2 and parententitytype = 121;
Reply With Quote
  #3 (permalink)  
Old 10-13-03, 23:39
Raj Shekhar Raj Shekhar is offline
Registered User
 
Join Date: Jun 2003
Posts: 38
Re: Exception handling in User Defined Function

Quote:
Originally posted by achiola
test this:

Select PARENTENTITYID into l_var from umlcompositestate where compositestateid = l_var and modelid =2 and parententitytype = 121;
Hi,

The select into clause doesnot work inside a function.
Secondly , I wanted to know whether exception handling is possible in udfs and if yes then how can I do that. In my code snippet that I have posted, I am getting errors while handling exceptions. whereas similar things work in procedures.

Thanks,
Raj
__________________
Raj Shekhar
Reply With Quote
  #4 (permalink)  
Old 10-14-03, 08:09
Raj Shekhar Raj Shekhar is offline
Registered User
 
Join Date: Jun 2003
Posts: 38
Re: Exception handling in User Defined Function

Quote:
Originally posted by Raj Shekhar
Hi,

The select into clause doesnot work inside a function.
Secondly , I wanted to know whether exception handling is possible in udfs and if yes then how can I do that. In my code snippet that I have posted, I am getting errors while handling exceptions. whereas similar things work in procedures.

Thanks,
Raj
can I do a select into clause in an UDF. Its giving me error.How to do that.
__________________
Raj Shekhar
Reply With Quote
  #5 (permalink)  
Old 10-14-03, 08:44
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Re: Exception handling in User Defined Function

Raj,
You cannot use the SELECT INTO, but you can do:

SET l_var = (Select PARENTENTITYID from umlcompositestate where compositestateid = l_var and modelid =2 and parententitytype = 121);

HTH

Andy

Quote:
Originally posted by Raj Shekhar
can I do a select into clause in an UDF. Its giving me error.How to do that.
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