建立預存程序:
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);
call ordertotal(20005,1,@total);
SELECT @total;
以上就是mysql智能存儲過程的內容,更多相關內容請關注PHP中文網(www.php.cn)!