mysql存储过程学习
# 创建一个名为procedure_test 存储过程。 DELIMITER $$ CREATE PROCEDURE `test`.`procedure_test`() BEGIN SELECT * FROM blogs; END$$ DELIMITER ; #调用存储过程 CALL procedure_test();
#删除存储过程 DROP PROCEDURE procedure_test;
#输出变量 DELIMITER $$ CREATE PROCEDURE `test`.`procedure_test2`( OUT pl DECIMAL(8,2), #输出参数1 OUT ph DECIMAL(8,2), #输出参数2 OUT pa DECIMAL(8,2) #输出参数3 ) BEGIN SELECT MIN(prod_price) INTO pl #传值1 FROM products; SELECT MAX(prod_price) INTO ph #传值2 FROM products; SELECT AVG(prod_price) INTO pa #传值3 FROM products; END $$ DELIMITER $$
#创建输入输出存储过程 DELIMITER $$ CREATE PROCEDURE procedure_test3( IN onnumber INT, #输出值 OUT ototal DECIMAL(8,2) #输出值 ) BEGIN SELECT SUM(item_price * quantity) FROM orderitems WHERE order_num = onnmuber INTO ototal; END$$ DELIMITER $$ #调用存储过程 CALL procedure_test3(20005 ,@total); #查看结果 select @total;
转载保留链接