Skip to content

Instantly share code, notes, and snippets.

@JRGGRoberto
Last active August 29, 2015 14:05
Show Gist options
  • Save JRGGRoberto/e0c6abf78a2f1b5cdc97 to your computer and use it in GitHub Desktop.
Save JRGGRoberto/e0c6abf78a2f1b5cdc97 to your computer and use it in GitHub Desktop.
Cursor em MySQL
DELIMITER $$
DROP PROCEDURE IF EXISTS teste $$
CREATE PROCEDURE teste()
BEGIN
DECLARE v_finished INTEGER DEFAULT 0;
--Declara??o das variaveis
DECLARE v_email varchar(100) DEFAULT "";
DECLARE v_fone varchar(100) DEFAULT "";
-- declare cursor
DEClARE cur CURSOR FOR
select party_name, primary_phone_number from mediador;
-- declare NOT FOUND handler
DECLARE CONTINUE HANDLER
FOR NOT FOUND SET v_finished = 1;
OPEN cur;
get_cur: LOOP
FETCH cur INTO v_email, v_fone;
IF v_finished = 1 THEN
LEAVE get_cur;
END IF;
-- build Execu??o
insert into nomes(nome) value (v_email);
insert into tel(tele) value (v_fone);
END LOOP get_cur;
CLOSE cur;
END$$
DELIMITER ;
@JRGGRoberto
Copy link
Author

Exemplo de cursor em MySQL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment