mysql存储过程变量没有被赋值
我想做自动碎片整理脚本,
BEGIN
#Routine body goes here...
declare tablename varchar(30);
declare move_sql varchar(30);
declare row int;
获得所有的表名:
declare cur cursor for select table_name from information_schema.tables where table_schema='crm';
先清空整理结果:
delete from shrink_result;
open cur;
my_loop:loop
begin
获得表名:
fetch cur into tablename;
把表名插入到整理结果中,这个结果是正确的,可以看到不同的表名都被塞进来了。
insert into shrink_result (table_name) values(tablename);
可是到这步,tablename这个变量又成个字符串了
## begin optmize operation
optimize table tablename;
end;
END LOOP my_loop;
close cur;
END
报错如下:
operation failed
Table 'crm.tablename' doesn't exist (crm是我在使用的库名。)