mysql存储过程
Posted coshaho
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql存储过程相关的知识,希望对你有一定的参考价值。
1、 简单的存储过程创建
drop procedure if exists selectOrder; DELIMITER // CREATE DEFINER=`root`@`localhost` PROCEDURE `selectOrder`() BEGIN select * from order_h; END // call selectOrder();
2、 带入参的存储过程创建
drop procedure if exists selectOrder; DELIMITER // CREATE PROCEDURE `selectOrder`(in customer varchar(32)) BEGIN select * from order_h where customerid=customer; END // call selectOrder(\'ct9\');
3、 带出参的存储过程创建
drop procedure if exists selectOrder; DELIMITER // CREATE PROCEDURE `selectOrder`(out money int) BEGIN select sum(summoney) into money from order_h where customerid=\'ct9\'; END // call selectOrder(@money); SELECT @money FROM DUAL;
4、 带有入参出参的存储过程创建
drop procedure if exists selectOrder; DELIMITER // CREATE PROCEDURE `selectOrder`(in customer varchar(32), out money int) BEGIN select sum(summoney) into money from order_h where customerid=customer; END // call selectOrder(\'ct1\', @money); SELECT @money FROM DUAL;
5、 存储过程控制语句
drop procedure if exists selectOrder; DELIMITER // CREATE PROCEDURE `selectOrder`(in customer varchar(32), in ismax boolean, out money int) BEGIN if ismax then select max(summoney) into money from order_h where customerid=customer; else select min(summoney) into money from order_h where customerid=customer; end if; /** 其他语法 申明变量 DECLARE s int; while循环 WHILE i <= n DO set s = s + i; END WHILE; case when CASE type WHEN 0 THEN set c = \'false\'; WHEN 1 THEN set c = \'true\'; ELSE set c = \'else\'; END CASE; */ END // call selectOrder(\'ct1\', false, @money); SELECT @money FROM DUAL;
以上是关于mysql存储过程的主要内容,如果未能解决你的问题,请参考以下文章