在存储过程中怎样 把EXECUTE strsql 后值 赋值给变量

MySql 码拜 8年前 (2016-02-06) 1398次浏览
在存储过程中怎样 把EXECUTE strsql 后值 赋值给变量 如
SET @strsql = CONCAT(
#”select sql_calc_found_rows  @rowindex:=@rowindex+1 as rownumber,” #记录行号
“select count(0) ”
,” from ”
,_tables
,CASE IFNULL(_where, “”) WHEN “” THEN “” ELSE CONCAT(” where “, _where) END
);
PREPARE strsql FROM @strsql;#定义预处理语句
EXECUTE strsql ; #执行预处理语句
DEALLOCATE PREPARE strsql; #删除定义
解决方案

40

用一个session变量传出来
CREATE PROCEDURE test()
begin
declare tmp int;

set @sql = “select count(*) into @count_tmp from tb1”;
prepare stmt from @sql;
execute stmt;
set tmp = @count_tmp;
deallocate prepare stmt;
end


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明在存储过程中怎样 把EXECUTE strsql 后值 赋值给变量
喜欢 (0)
[1034331897@qq.com]
分享 (0)