MySQL存储过程中如何保存select count(*)的结果为整数

码丁农 2011-04-16 05:44:36
....
....
....
declare cnt_model int default 0;

set @stmt2 = concat("select count(1) from WareModel where TypeID = '", @t_typeid, "' into @t_model");
prepare s2 from @stmt2;
execute s2;
DEALLOCATE PREPARE s2;
set @stmt2 = NULL;

请问,如何把@t_model赋给cnt_model?

while i_model < cnt_model DO
...
...
...
...全文
224 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
rucypli 2011-04-16
  • 打赏
  • 举报
回复
set @stmt2 = concat("select count(1) from WareModel where TypeID = '", @t_typeid, "' into @t_model");
不用拼动态sql



select count(1) from WareModel where TypeID =@t_typeid into @t_model
set cnt_model =@t_model

56,677

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧