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 > Recursive procedures / functions

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-10-05, 12:08
dvtdbd dvtdbd is offline
Registered User
 
Join Date: Feb 2005
Location: Barcelona
Posts: 42
Recursive procedures / functions



Counting from 1 to 5 recursively...


* Recursive procedure (OK):


CREATE PROCEDURE suma (IN number INTEGER)
LANGUAGE SQL
BEGIN

DECLARE error_message CHAR(30);
DECLARE procedure_call CHAR(20);

SET number = number + 1;
IF number = 5 THEN
SET error_message = 'OK 5 recusive calls!';
SIGNAL SQLSTATE '75002'
SET MESSAGE_TEXT = error_message;
END IF;

-- DB2 recursive procedure call
SET procedure_call = 'CALL suma(?)';
PREPARE proc_exec FROM procedure_call;
EXECUTE proc_exec USING number;
END;


CALL suma(0);


* Recursive function (ERROR):


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

DECLARE error_message CHAR(30);
DECLARE function_call CHAR(20);

SET number = number + 1;
IF number = 5 THEN
SET error_message = '5 recusive calls';
SIGNAL SQLSTATE '75002'
SET MESSAGE_TEXT = error_message;
END IF;

-- DB2 recursive function call
SET function_call = 'CALL suma(?)';
PREPARE func_exec FROM function_call;
EXECUTE func_exec INTO number USING number;
END;


CALL suma(0);


Not recursive functions in DB2?

Reply With Quote
  #2 (permalink)  
Old 03-10-05, 14:57
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
You can't CALL a function, recursive or not.

Are you trying to write your own mathlib using DB2 SQL?
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