思路是获取数据的表名,然后拿到表名进行修改。
drop procedure if exists useCursor;
CREATE PROCEDURE useCursor()
BEGIN
DECLARE oneAddr varchar(36) default '';
DECLARE allAddr varchar(40) default '';
DECLARE done INT DEFAULT 0;
DECLARE curl CURSOR FOR select table_name from information_schema.tables where table_schema='数据库' and table_name like '表民_%';
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
OPEN curl;
REPEAT
FETCH curl INTO oneAddr;
IF not done THEN
set @sql=concat('alter table ',oneAddr," add 字段名 VARCHAR(32) NOT NUll DEFAULT '' COMMENT 'xxx'; ");
PREPARE stmt from @sql;
execute stmt;
END IF;
UNTIL done END REPEAT;
select allAddr;
CLOSE curl;
END;
call useCursor();