Home > Database > Mysql Tutorial > body text

mysql smart stored procedure

黄舟
Release: 2016-12-28 17:54:12
Original
1071 people have browsed it

Create stored procedure:

 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;
Copy after login

end;

Call stored procedure: taxable is true

call ordertotal(20005,1,@total );

SELECT @total;

Call stored procedure: taxable is false

call ordertotal(20005,1,@total);

SELECT @ total;

The above is the content of mysql intelligent stored procedure. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template