Created
May 23, 2018 20:41
-
-
Save saxenap/ad8b89fdc04891bb926fd10434c7ddd0 to your computer and use it in GitHub Desktop.
This file contains 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 `get_post`; | |
CREATE PROCEDURE `get_post`(postId INT) | |
BEGIN | |
# DECLARE num_rows INT; | |
# DECLARE i INT; | |
# DECLARE col_name VARCHAR(255); | |
# | |
# DECLARE col_names CURSOR FOR | |
# SELECT column_name | |
# FROM INFORMATION_SCHEMA.COLUMNS | |
# WHERE table_name = 'question' | |
# ORDER BY ordinal_position; | |
# | |
# OPEN col_names; | |
# | |
# SELECT FOUND_ROWS() INTO num_rows; | |
# | |
# SET i = 1; | |
# the_loop: LOOP | |
# | |
# IF i > num_rows THEN | |
# CLOSE col_names; | |
# LEAVE the_loop; | |
# END IF; | |
# | |
# FETCH col_names | |
# INTO col_name; | |
# | |
# DO WHAT YOU WANT WITH col_name | |
# | |
# SET i = i + 1; | |
# END LOOP; | |
END $$ | |
DELIMITER ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment