0

Can you tell me what's wrong with my codes? I followed MySQL loop through tables to loop the tables of one database. But I got nothing from iterating the cursor. The SELECT @sql; outputs NULL value. Thanks!

DROP PROCEDURE IF EXISTS seedinvest.insertDatabaseRowHash;
DELIMITER $$
CREATE PROCEDURE seedinvest.insertDatabaseRowHash(_schemaName varchar(100))
BEGIN
    DECLARE done INT DEFAULT FALSE;
    DECLARE table_name varchar(20);
    DECLARE table_cursor cursor for SELECT table_name FROM information_schema.tables
                                    WHERE table_schema = _schemaName;
    DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;

    OPEN table_cursor;

    table_loop: LOOP
        FETCH table_cursor INTO table_name;
        IF done THEN
            LEAVE table_loop;
        END IF;

        SET @sql = CONCAT('DESC ', _schemaName, '.', table_name);
        SELECT @sql; -- It outputs Null value
        PREPARE stmt FROM @sql;
        EXECUTE stmt;
        DROP PREPARE stmt;
    END LOOP;

    CLOSE table_cursor;

END$$


Error Code: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'NULL' at line 1
2
  • did you pass in a _schemaName? Commented Nov 11, 2016 at 23:02
  • Yes, I did. This is what I test using one real table. I revert it to the original one. Commented Nov 11, 2016 at 23:14

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.