数据库存储过程语法格式如下:
create procedure 过程名([[in|out|inout] 参数名 数据类型[,[in|out|inout] 参数名 数据类型…]]) [特性 ...] 过程体delimiter // create procedure myproc(out s int) begin select count(*) into s from students; end //delimiter ;
例:创建一个简单的存储过程
-- ------------------------------ procedure structure for `proc_adder`-- ----------------------------drop procedure if exists `proc_adder`;delimiter ;;create definer=`root`@`localhost` procedure `proc_adder`(in a int, in b int, out sum int)begin #routine body goes here... declare c int; if a is null then set a = 0; end if; if b is null then set b = 0; end if;set sum = a + b;end;;delimiter ;
执行以上存储结果,验证是否正确,如下图
set @b=5;call proc_adder(2,@b,@s);select @s as sum;
以上就是mysql存储过程的写法的详细内容。
