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 a procedure in a function

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-30-04, 13:21
Alairj Alairj is offline
Registered User
 
Join Date: Nov 2004
Location: São Paulo, Brazil
Posts: 32
Exclamation Problem calling a procedure in a function

Someone knows how can i call a procedure in a function body, i've been tried like this:

CREATE FUNCTION function1( p_dsc_ctx VARCHAR(7) ,
p_dsc_colunm VARCHAR(18))
LANGUAGE SQL
NOT DETERMINISTIC
MODIFIES SQL DATA
RETURNS VARCHAR(50)
BEGIN ATOMIC

DECLARE vReturn VARCHAR(50);

call procedure1( p_dsc_ctx, p_dsc_colunm , vReturn );

RETURN vReturn;
END

but this error occurs:

[IBM][CLI Driver][DB2/LINUX] SQL0628N Multiple or conflicting keywords involving the "MODIFIES SQL DATA" clause are present. LINE NUMBER=16. SQLSTATE=42613

Thanks
Reply With Quote
  #2 (permalink)  
Old 11-30-04, 14:04
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Calling SPs from UDF is not permitted for any version prior to 8.2.

Andy
Reply With Quote
  #3 (permalink)  
Old 11-30-04, 14:08
Alairj Alairj is offline
Registered User
 
Join Date: Nov 2004
Location: São Paulo, Brazil
Posts: 32
But in version 8.2 is permited and my db2 version is 8.2, you had already do something like this?

Thanks
Reply With Quote
  #4 (permalink)  
Old 11-30-04, 14:35
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
We are just now experimenting with 8.2 so we have not tried this yet. I looked at the grammar for CREATE FUNCTION because of the error message you posted. I think you need to move the RETURNS clause like this:

CREATE FUNCTION function1( p_dsc_ctx VARCHAR(7) ,
p_dsc_colunm VARCHAR(18))
RETURNS VARCHAR(50)
LANGUAGE SQL
NOT DETERMINISTIC
MODIFIES SQL DATA
BEGIN ATOMIC

DECLARE vReturn VARCHAR(50);

call procedure1( p_dsc_ctx, p_dsc_colunm , vReturn );

RETURN vReturn;
END

HTH
Andy
Reply With Quote
  #5 (permalink)  
Old 11-30-04, 15:33
Alairj Alairj is offline
Registered User
 
Join Date: Nov 2004
Location: São Paulo, Brazil
Posts: 32
I tried to do what you said but the error message continue, i'll try to find a solution for this case, if you find one please tell me.

Thanks a lot.
Reply With Quote
  #6 (permalink)  
Old 11-30-04, 15:40
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
What happens when you leave out the "MODIFIED SQL DATA" clause?

Andy
Reply With Quote
  #7 (permalink)  
Old 12-01-04, 10:20
Alairj Alairj is offline
Registered User
 
Join Date: Nov 2004
Location: São Paulo, Brazil
Posts: 32
I think i found the reason of my problem, i put the same name for the procedure, function and the global temporary table that the procedure reads i think db2 don't know in this case what are the statement he'll call, i change the name of then and db2 permits me to compile then.

Thanks a lot.
Reply With Quote
  #8 (permalink)  
Old 01-28-05, 16:31
allian allian is offline
Registered User
 
Join Date: Dec 2004
Posts: 54
Can you post you example, what did you do to achieve for calling Sp from UDF?
Reply With Quote
  #9 (permalink)  
Old 01-28-05, 17:41
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
It is hard to believe that db2 will be confused when using same name for a routine ,a function and a table .. Each one of them is a different type of object and used in a different fashion ... So, it has to be something else ...

I have used UDFs and SPs with the same name before

Cheers
Sathyaram
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
  #10 (permalink)  
Old 01-30-05, 18:50
jacampbell jacampbell is offline
Registered User
 
Join Date: Jan 2005
Posts: 191
My local installation of the documentation indicates that MODIFIES SQL DATA is "Valid only if RETURNS specifies a table (TABLE column-list)".

James Campbell
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