Last active
August 29, 2015 14:05
-
-
Save JRGGRoberto/e0c6abf78a2f1b5cdc97 to your computer and use it in GitHub Desktop.
Cursor em MySQL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Exemplo de cursor em MySQL