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智能存储过程的内容。