作者:晶晶9930_195 | 来源:互联网 | 2023-09-11 22:03
Ihaveadatabasewheretemptablesarecreated,thosetablenamesarerandomlygeneratedandsaved
I have a database where temp tables are created, those table names are randomly generated and saved in Checkouts.unid. I want to drop all those tables and truncate the table Checkouts. I thought the niftiest solution would be a procedure, but it will not work:
我有一个创建临时表的数据库,这些表名是随机生成的并保存在Checkouts.unid中。我想删除所有这些表并截断表Checkouts。我认为最麻烦的解决方案是一个程序,但它不起作用:
DROP PROCEDURE IF EXISTS `spCheckoutsCleanup`;
CREATE PROCEDURE `spCheckoutsCleanup` ()
SQL SECURITY INVOKER
BEGIN
DECLARE `t` VARCHAR(64);
DECLARE `ch` CURSOR FOR SELECT `unid` FROM `Checkouts`;
OPEN `ch`;
drop_tables: LOOP
FETCH `ch` INTO `t`;
DROP TABLE IF EXISTS `t`;
END LOOP;
CLOSE `ch`;
TRUNCATE TABLE `Checkouts`;
END
I always get "No data - zero rows fetched, selected, or processed" although those tables are there and the table Checkouts is not empty though.
我总是得到“没有数据 - 零行提取,选择或处理”,虽然这些表在那里,表Checkouts不是空的。
2 个解决方案