Results 1 to 1 of 1
  1. #1
    Join Date
    Feb 2005
    Location
    Barcelona
    Posts
    42

    Angry Unanswered: 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 09:17.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •