- 论坛徽章:
- 9
|
简单的写了下,没详细测试,也没加事务,需要的话可以自己包裹~~:wink:
- delimiter $
- drop procedure if exists group_insert$
- create procedure group_insert (in new_s_id varchar(10),in new_o_id varchar(10),in new_num int)
- begin
- if (num=1)
- then
- insert into T1 (`s_id`, `o_id`, `num`) values (new_s_id,new_o_id,new_num);
- insert into T2 (`s_id`, `o_id`, `1`) values (s_id,o_id,1) on duplicate key update `1` = `1`+1 ;
- end if;
- if (num=2)
- then
- insert into T1 (`s_id`, `o_id`, `num`) values (s_id,o_id,num);
- insert into T2 (`s_id`, `o_id`, `2`) values (s_id,o_id,1) on duplicate key update `1` = `1`+1 ;
- end if;
- if (num=3)
- then
- insert into T1 (`s_id`, `o_id`, `num`) values (s_id,o_id,num);
- insert into T2 (`s_id`, `o_id`, `3`) values (s_id,o_id,1) on duplicate key update `1` = `1`+1 ;
- end if;
- end$
- delimiter ;
复制代码 |
|