Created
September 7, 2016 14:25
-
-
Save arieljannai/8325a13f1e2d8f80ed5cb6b816754a3d to your computer and use it in GitHub Desktop.
Loop all tables for something
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
DROP PROCEDURE IF EXISTS loopTables; | |
DELIMITER // | |
CREATE PROCEDURE `loopTables` () | |
BEGIN | |
DECLARE curr_table VARCHAR(200); | |
DECLARE cursor_tables CURSOR FOR select table_name from information_schema.tables where table_schema = (SELECT DATABASE()); | |
OPEN cursor_tables; | |
grant_loop: LOOP | |
FETCH cursor_tables INTO curr_table; | |
-- do something | |
IF done THEN | |
LEAVE grant_loop; | |
END IF; | |
END LOOP; | |
CLOSE cursor_tables; | |
END // | |
DELIMITER ; | |
CALL loopTables(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment