言寸

导航

mysql 5.7.20 取得动态sql执行结果

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();

 

posted on 2019-05-10 10:35  言寸  阅读(1539)  评论(0编辑  收藏  举报