首页  >  文章  >  数据库  >  mysql智能存储过程

mysql智能存储过程

黄舟
黄舟原创
2016-12-28 17:54:121079浏览

创建存储过程:

 CREATE procedure ordertotal(
in onumber 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 = onumber into total; 
if taxable then 
SELECT total+(total/100*taxrate) into total; 
end if; 
SELECT total into ototal;

end;

调用存储过程:taxable为真

call ordertotal(20005,1,@total);

SELECT @total;

调用存储过程:taxable为假

call ordertotal(20005,1,@total);

SELECT @total;

 以上就是mysql智能存储过程的内容,更多相关内容请关注PHP中文网(www.php.cn)!


声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn