标签:变量 into cal ase drop ima arc bool iter
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;
标签:变量 into cal ase drop ima arc bool iter
原文地址:http://www.cnblogs.com/coshaho/p/7500370.html