drop procedure drop_copy;
create PROCEDURE drop_copy()
begin
DECLARE merchantName VARCHAR(255);
DECLARE done INT DEFAULT 0;
DECLARE cur CURSOR FOR
select table_name as merchantName from information_schema.tables
where table_schema ='group_ad' and table_name like '%_copy1';
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done=1;
OPEN cur;
posLoop:LOOP
FETCH cur INTO merchantName;
IF done=1 THEN LEAVE posLoop;
END IF;
select now();
set @stmt = concat('drop table ',merchantName);
PREPARE stmt from @stmt;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END LOOP posLoop;
CLOSE cur;
end;
|