开发者

MySQL cursor rename tables, script error

I am new to MySQL, and I have a sc开发者_运维技巧ript that is supposed to rename all tables to uppercase. I have an error in it , but I can't figure out why it is not working. Any help is appreciated!

DECLARE a VARCHAR(100);
DECLARE done INT DEFAULT 0;

DECLARE cur1 CURSOR FOR 
    SELECT DISTINCT table_name 
    FROM information_schema.columns 
    WHERE table_schema='admin27_shop';

DECLARE CONTINUE HANDLER FOR NOT FOUND SET done=1;

OPEN cur1;

read_loop: LOOP
    FETCH cur1 INTO a;
    IF done THEN
        LEAVE read_loop;
    END IF;

    CREATE TABLE CONCAT(a, '1') SELECT * FROM a;
    DROP TABLE a;
    RENAME TABLE CONCAT(a, '1') TO UPPER(a);
END LOOP;

CLOSE cur1;

UPDATE: The error message happens on line 1, at the declaration of the variable, says that there is a syntax error...


Must be my specific version of MySQL and the application. Closing this question.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜