Jump to content

stored procedure cursor set in an if ???


minus4

Recommended Posts

hi there, i have the need to run 2 different SQL statements depending on what info i receive, i have put together an example stored procedure that errors on the DECLARE cur1 line.

 

DELIMITER $$

DROP PROCEDURE IF EXISTS sp_TEST $$

CREATE PROCEDURE sp_TEST(IN tester INT)
BEGIN


DECLARE done INT DEFAULT 0;
DECLARE prodid INT DEFAULT 0;
DECLARE mysql TEXT;

IF (tester=1) THEN
DECLARE cur1 CURSOR FOR SELECT productId FROM products WHERE live=1; < -- ERROR HERE
ELSE
DECLARE cur1 CURSOR FOR SELECT productId FROM products WHERE live=0;
END IF;


DECLARE CONTINUE HANDLER FOR NOT FOUND SET done=1;


OPEN cur1;
FETCH cur1 INTO prodid;
REPEAT

UNTIL done END REPEAT;
CLOSE cur1;


SELECT prodid;


END $$
DELIMITER ;

 

ERROR: you have an error in your sql syntax blah blah........... (1064)

please don't concentrate on what it delivers or what the procedure might do, the problem is with the IF statement.

 

Would appreciate your help if thats possible.

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/150881-stored-procedure-cursor-set-in-an-if/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.