mysql获取动态sql返回值
时间:2009-06-02 来源:sss0213
摘自:http://topic.csdn.net/u/20080512/21/2440e437-02ad-41af-bda8-c9fba86c4e01.html
set @aSql="select count(id),sum(price) into @tclick,@todayTotalrom adnote where 1=1 ";
prepare sqlstmt from @aSql;
execute sqlstmt;
你之后
select @tclick;
或者赋给一个OUT 变量就可以了。 如(摘自:http://jonllen.javaeye.com/blog/370343):
prepare sqlstmt from @aSql;
execute sqlstmt;
你之后
select @tclick;
或者赋给一个OUT 变量就可以了。 如(摘自:http://jonllen.javaeye.com/blog/370343):
- #拼接查询总记录的SQL语句
- set v_sqlcounts = concat('select count(*) into @recordcount from ',v_tables,v_where);
- set @sqlcounts := v_sqlcounts;
- #预处理动态SQL
- prepare stmt from @sqlcounts;
- #传递动态SQL内参数
- set @s1= categoryid;
- execute stmt using @s1;
- deallocate prepare stmt;
- #获取动态SQL语句返回值
- set recordcount = @recordcount;
以上我上再做存储过程分页里用到动态SQL里将查询到的count记录条数通过变量@recordcount放到recordcount里面了。
相关阅读 更多 +