Skip to content

Instantly share code, notes, and snippets.

@markbalt
Created June 2, 2015 19:05
Show Gist options
  • Save markbalt/720f21ad02b67b4f6ff7 to your computer and use it in GitHub Desktop.
Save markbalt/720f21ad02b67b4f6ff7 to your computer and use it in GitHub Desktop.
Customer MySQL Cursor
DROP PROCEDURE IF EXISTS curupdate;
delimiter //
CREATE PROCEDURE curupdate()
BEGIN
DECLARE done INT DEFAULT 0;
DECLARE a INT;
DECLARE b CHAR(16);
DECLARE cur1 CURSOR FOR SELECT id,vantive_id FROM customer;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
OPEN cur1;
REPEAT
FETCH cur1 INTO a, b;
IF NOT done AND b IS NOT NULL THEN
INSERT INTO vantive_customer (customer_id, vantive_id) VALUES (a,b);
END IF;
UNTIL done END REPEAT;
CLOSE cur1;
END
//
DELIMITER ;
call curupdate();
DROP PROCEDURE IF EXISTS curupdate;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment