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 > Problem calling procedure from UDF

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-14-07, 08:19
italianboy italianboy is offline
Registered User
 
Join Date: Jun 2007
Posts: 6
Question Problem calling procedure from UDF

Hello,

I have a function which tries to call a procedure. But for some reason I'm getting the error SQL0374N The "MODIFIES SQL DATA" clause has not been specified in the CREATE FUNCTION statement for LANGUAGE SQL function "myschema.my_func". When I put the clause I'm getting SQL0628N Multiple or conflicting keywords involving the "MODIFIES SQL DATA" clause are present. How could I fix it? Here are my function and procedure definitions :

CREATE PROCEDURE myschema.my_proc(IN id INTEGER, IN F_DATE DATE, OUT res VARCHAR(7))
P1: BEGIN
DECLARE rs_atr char(4);
DECLARE rs_dstart date;
DECLARE rs_dstop date;
DECLARE eors INT DEFAULT 0;
DECLARE not_found CONDITION FOR SQLSTATE '02000';
DECLARE rowVar CURSOR FOR select ...
from ...
where ...;
DECLARE CONTINUE HANDLER FOR not_found SET eors = 1;

OPEN rowVar;
FETCH rowVar INTO rs_dstart, rs_dstop, rs_atr;

SET res = '-------';

WHILE eors = 0 DO
IF RTRIM(rs_atr) = 'KD' THEN
SET res = '1234567';
ELSEIF RTRIM(rs_atr) = 'B' THEN
SET res = LEFT(res, 5) || '67';
ELSEIF RTRIM(rs_atr) = 'D' THEN
SET res = '12345' || RIGHT(res, 2);
ELSEIF (RTRIM(rs_atr) >= '1' AND RTRIM(rs_atr) <= '7') THEN
SET res = LEFT(res, INT(RTRIM(rs_atr)) - 1) || RTRIM(rs_atr) || RIGHT(res, 7 - INT(RTRIM(rs_atr)));
END IF;
FETCH rowVar INTO rs_dstart, rs_dstop, rs_atr;
END WHILE;

CLOSE rowVar;
END P1

CREATE FUNCTION myschema.my_func(ID integer, dateStr varchar(50))
RETURNS VARCHAR(7)
F1: BEGIN ATOMIC

DECLARE result varchar(7);
DECLARE f_date date;

SET f_date = date(dateStr);

call myschema.my_proc(ID, f_date, result);
RETURN result;
END

Thanks in advance
Reply With Quote
  #2 (permalink)  
Old 12-14-07, 08:26
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
If you read the manual for CREATE FUNCTION, the clause MODIFIES SQL DATA is only valid for functions returning a table, not for a scalar function like yours.

Andy
Reply With Quote
  #3 (permalink)  
Old 12-14-07, 08:39
italianboy italianboy is offline
Registered User
 
Join Date: Jun 2007
Posts: 6
Re: Problem calling procedure from UDF

I've put this clause only because I've got an error message. Anyway I still don't know how to fix this problem.
Reply With Quote
  #4 (permalink)  
Old 12-14-07, 08:42
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Which DB2 version and OS are you using?

Andy
Reply With Quote
  #5 (permalink)  
Old 12-14-07, 08:45
italianboy italianboy is offline
Registered User
 
Join Date: Jun 2007
Posts: 6
Re: Problem calling procedure from UDF

DB2 ver. 8.1.15. Enterprise Server Edition

OS: Win XP Pro
Reply With Quote
  #6 (permalink)  
Old 12-14-07, 08:57
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
I think you are out of luck with this method. Maybe if you changed the stored procedure to a UDF it might work.

Andy
Reply With Quote
  #7 (permalink)  
Old 12-14-07, 09:06
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
Create the procedure using the READS SQL DATA or CONTAINS SQL clauses. Your procedure (as shown above) doesn't do data modifications, so this should be sufficient. Once the procedure is READS SQL DATA/CONTAINS SQL, you can create your UDF as-is.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #8 (permalink)  
Old 12-14-07, 09:23
italianboy italianboy is offline
Registered User
 
Join Date: Jun 2007
Posts: 6
Re: Problem calling procedure from UDF

Yes, that did the trick. Thank you!
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