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 ;