drop procedure test;
delimiter ;;
CREATE procedure test()
-- 取动态sql的值
begin
DECLARE v_sqlcounts varchar(500);
DECLARE recordcount varchar(500);
set v_sqlcounts = concat('select 44 into @recordcount from dual');
set @sqlcounts := v_sqlcounts;
#预处理动态SQL
prepare stmt from @sqlcounts;
execute stmt;
deallocate prepare stmt;
#获取动态SQL语句返回值
set recordcount = @recordcount;
SELECT recordcount;
end
;;
delimiter ;
call test();
mysql 5.7.20 取得动态sql执行结果
点赞
收藏