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 > EXECUTE IMMEDIATE (Dynamic Call)

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-08-05, 05:50
dvtdbd dvtdbd is offline
Registered User
 
Join Date: Feb 2005
Location: Barcelona
Posts: 42
Angry EXECUTE IMMEDIATE (Dynamic Call)



Initial situation:

When a function or procedure calls other ones, the creation order must be ascending, from the most sheltered function or procedure to which makes first call. But in recursivity case (routine which calls itself) it enters conflict, due to the referenced routine (which must exist), is the same one that makes the call.


Example of recursive function:

CREATE FUNCTION fibonacci (number integer)
RETURNS integer
NO EXTERNAL ACTION NOT DETERMINISTIC READS SQL DATA
BEGIN ATOMIC

IF number = 0 OR number = 1 THEN
RETURN 1;
ELSE
RETURN fibonacci(number - 1) + fibonacci(number - 2);
END IF;

END;

SQLSTATE 42884


Solution:

Using dynamic call (with EXECUTE IMMEDIATE clause), function would be something like this:

[...]
SET m_call = 'CALL fibonacci (' || number || ')';
EXECUTE IMMEDIATE m_call;
[...]

Where m_call is a variable defined like char...


Question:

What about the return value? How would be exactly fibonnacci function with dynamic call?


Last edited by dvtdbd; 03-08-05 at 08:17.
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