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
都不行!
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]
MYSQL中不行,
select @d:=count + in_count ....