MySQL爬坑:
在存储过程中,想在concat中使用select into,into后的变量要只用带@符号的,参考如下
BEGIN
Declare TotalCountSql varchar(500);
SET @TotalCountSql= 'select count(1) into TotalRecord from t_zhangdan;';
PREPARE stmtC FROM @TotalCountSql;
EXECUTE stmtC;
DEALLOCATE PREPARE stmtC;
select @TotalRecord;
Error Code: 1327. Undeclared variable: TotalRecord
将上面的改一下就行了:
SET @TotalCountSql= CONCAT('select count(1) into @TotalRecord1 from ' ,TableName);#总记录数语句
PREPARE stmtC FROM @TotalCountSql;
EXECUTE stmtC;
set TotalRecord = @TotalRecord1;
DEALLOCATE PREPARE stmtC;
或者:
SET @TotalCountSql= CONCAT('select username from ' ,TableName);#总记录数语句
PREPARE stmtC FROM @TotalCountSql;
EXECUTE stmtC;
set TotalRecord = FOUND_ROWS();