BEGIN
DECLARE strClear VARCHAR(256);
DECLARE done INT DEFAULT 0;
#定义游标
DECLARE curOne CURSOR FOR select concat(‘truncate table ‘,table_name,‘;‘) from information_schema.TABLES where table_schema=‘test‘;
#绑定控制变量到游标,游标循环结束自动转为True
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
#打开游标
OPEN curOne;
REPEAT
FETCH curOne INTO strClear;
#SELECT strClear;
#动态执行SQL语句
SET @mysql = strClear;
PREPARE stmt from @mysql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
UNTIL done = 1 END REPEAT;
#关闭游标
CLOSE curOne;
END
原文地址:https://www.cnblogs.com/lovemj/p/9209228.html
时间: 2024-10-28 19:07:14