e.g. CALL productpricing(@pricelow, @pricehigh, @priceaverage);
创建存储过程
需要注意的是,默认的MySQL语句分隔符为;如果要解释存储过程自身内的;那么会出现语法错误
解决方法是 在存储过程之前定义DELIMITER // 临时将语句分隔符定义为//或其他字符,在存储过程之后DELIMITER ; 将分隔符重新定义为;
e.g.
CREATE PROCEDURE ordertotal(
IN onumber INT,
IN taxable BOOLEAN,
OUT ototal DECIMAL(8,2)
) COMMENT 'Obtain order total, optionally adding tax'
BEGIN
-- Declare variable for total
DECLARE total DECIMAL(8,2);
-- Declare tax percentage
DECLARE taxrate INT DEFAULT 6;
-- Get the order total
SELECT Sum(item_price*quantity)
FROM orderitems
WHERE order_num = onumber
INTO total;
-- Is this taxable?
IF taxable THEN
-- Yes, so add taxrate to the total
SELECT total+(total/100*taxrate) INTO total;
END IF;
-- And finally, save to out variable
SELECT total INTO ototal;
END;
CALL ordertotal(20005, 0, total);
SELECT @total;
删除存储过程
DROP PROCEDURE productpricing;
检查存储过程
SHOW CREATE PROCEDURE ordertotal; 查看一个存储过程的CREATE语句
SHOW PROCEDURE STATUS LIKE 'ordertotal';