存储过程
1.创建存储过程:
create procedure show(in id int)
begin
select * from sc where xuehao=id;
end
2.使用存储过程:
call show(10)
3.复杂操作:
drop procedure show; //删除存储过程;
create procedure show(in id int)
begin
declare couts int
select count(*) into cous from sc where xuehao = id;
if couts=0
then select "用户不存在"
else
select * from sc where xuhao = id
end if
end
call show(100)
4.传入多个参数
create procedure show(in id int,in name varchar(255))
.......
5.创建购物车的存储过程,传入商品id,用户id,购买数量
create procedure shop(in goods varchar(255),in id int,in x int)
begin
declear user int
declear qt int
select count(*)into user,quanlity into qt form shopcar where id=id and goodsid=goodsid
if coun = 0
then
insert into shopcar(goodsid,id) values(goodsid,id);
else
update shopcar set quantity=qt+x
endif
end
shop(10,001,1000);