Tuesday, July 27, 2010

New MySQL 5 stored procedures

Seems the old syntax of my stored procedure creation doesn't work in MySQL 5. Don't use $$ as a delimiter anymore!

Here's my NEW sample for you. I included a cursor.

DELIMITER |
CREATE PROCEDURE sp_my_stored_proc()
BEGIN

declare done int default 0;
declare n_value bigint default 0;
declare str_value varchar(200) default '';
declare cur1 cursor for select the_id, the_val from my_table;
declare continue handler for not found set done=1;

open cur1;
repeat
fetch cur1 into n_value, str_value;

if not done then
[multiple statements can go here, each terminated by ;]
end if;

UNTIL done END REPEAT;
CLOSE cur1;
END |

No comments: