1.创建存储过程:
在命令行创建一个名为ordertotal的存储过程:
DELIMITER //
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
//2.存储过程的调用:
CALL ordertotal(20005,0,@total);调用了1中的存储过程。
查看返回的结果
select @total;3.查看已经存在的存储过程方法一:
select `name` from mysql.proc where db = 'your_db_name' and `type` = 'PROCEDURE'方法二:show procedure status;4.查看存储过程的创建代码
show create procedure proc_name;
创建与调用MySQL存储过程
4万+

被折叠的 条评论
为什么被折叠?



