mysql写过哪些存储过程_写一个mysql的存储过程

--procedure name: ordertotal

--parameters: onnumber = order number

--      taxable = 0 if not taxable, 1 if taxable

--      ototal = order total variable

CREATE PROCEDURE ordertotal (

in onnumber int,

in taxable boolean,

out ototal decimal(8,2)

) comment 'obtain order total, optionally adding tax'

BEGIN

--先声明变量

declare total decimal(8,2);

declare taxrate int default 6;

--计算

select sum(item_price*quantity)

from orderitems

where order_num = onnumber

into total;

--是否需要纳税?由你传的参数决定

if taxable then

select total + (total/100*taxrate) into total;

end if;--必须if和end if配对,也可以用elseif,顺序执行

--最后当然把结果赋给out的ototal

select total into ototal;

END;

--要试验这个存储过程,要用如下语句

call ordertotal(2001,1,@total);

select @tatal;

--备注:1、显示创建一个存储过程的create语句,使用show create procedure ordertotal;

--2、为了获得何时、由谁创建等详细信息的存储过程列表,使用show procedure status,当然,这条语句你还可以加like进行过滤,如

--show procedure status like 'ordertotal';

--3、这个过程比较简单,但很多方面都介绍到了。mark.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值