MySQL Forums
Forum List  »  Stored Procedures

Re: Dynamic Cursor
Posted by: Alan Gong
Date: July 02, 2019 01:27PM

Sorry if this was covered under a different thread. I am new to MySQL. I am trying to create a stored program with a cursor and I am not able to get the stored program to compile. I have looked at the example in: http://www.mysqltutorial.org/mysql-cursor/

If I comment out the code around the cursor definition and setting of the output parameters, the stored program compiles. Any insight will be appreciated.

I am getting the following compile error:
Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'cursor currDateTime cursor for select now() current_date_time; DECLARE CONTIN' at line 7


DELIMITER $$
CREATE PROCEDURE ECOMADMIN.GET_CURRENT_DATETIME( OUT p_ReturnCode DOUBLE, OUT p_ReturnDesc VARCHAR(4000) )
BEGIN

DECLARE finished INTEGER DEFAULT 0;
DECLARE v_dateTime datetime default current_date();

cursor currDateTime cursor for
select now() current_date_time;

DECLARE CONTINUE HANDLER
FOR NOT FOUND SET finished = 1;

OPEN currDateTime;

get_results: LOOP
FETCH currDateTime INTO v_dateTime;
If finished = 1 then
leave get_results;
end if;
END LOOP get_results;

SET p_ReturnCode = 0;
SET p_ReturnDesc = 'success';
END$$
DELIMITER ;

Options: ReplyQuote


Subject
Views
Written By
Posted
1509
April 08, 2019 08:03PM
392
April 08, 2019 08:55PM
Re: Dynamic Cursor
1263
July 02, 2019 01:27PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.