MYSQL 存储过程变量赋值的问题

qiunet 2013-02-26 02:57:08

delimiter //
CREATE PROCEDURE global_shops(
in_item_id int(10),
in_max_count int(10),
in_count int(10),
OUT out_can_buy tinyint(2)
)
BEGIN
declare currcount int(10);
declare can_buy tinyint(2);
START TRANSACTION;
update g_shop set count = count + in_count where item_id = in_item_id;
select count into currcount from g_shop where item_id = in_item_id;
if( currcount <= in_max_count) then
set out_can_buy = 1;
COMMIT;
else
set out_can_buy = 0;
ROLLBACK;
end if;
END
//
DELIMITER ;


MYSQL
想知道.怎么在update那个语句中就给currcount 赋值了.而不用select into实现!求教了

我使用过:
update g_shop set currcount = count = count + in_count
update g_shop set @currcount := count = count + in_count
都不行!
...全文
138 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
WWWWA 2013-02-26
  • 打赏
  • 举报
回复
在SQLSERVER、SYBASE(ASA、ASE)中可以UPDATE变量 MYSQL中不行, select @d:=count + in_count ....
rucypli 2013-02-26
  • 打赏
  • 举报
回复
没想到有能在update语句中赋值的,也没那语法支持 Single-table语法: UPDATE [LOW_PRIORITY] [IGNORE] tbl_name SET col_name1=expr1 [, col_name2=expr2 ...] [WHERE where_definition] [ORDER BY ...] [LIMIT row_count] Multiple-table语法: UPDATE [LOW_PRIORITY] [IGNORE] table_references SET col_name1=expr1 [, col_name2=expr2 ...] [WHERE where_definition]

56,679

社区成员

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

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