MySQL--带有inout的存储过程
#带有inout模式参数的存储过程
1 案例一:传入a和b两个值,最终a和b的值翻倍并返回 2 delimiter $ 3 create PROCEDURE myp9(inout a int,inout b int) 4 begin 5 set a=a*2; 6 set b=b*2; 7 end $ 8 9 调用过程 10 先设置两个用户变量 11 set @m=10$ 12 set @n=20$ 13 然后调用 14 call myp9(@m,@n)$ 15 select @m,@n$--最后查看结果
运行结果:
1 mysql> delimiter $ 2 create PROCEDURE myp9(intout a int,inout b int) 3 begin 4 set a=a*2; 5 set b=b*2; 6 end $ 7 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'a int,inout b int) 8 begin 9 set a=a*2; 10 set b=b*2; 11 end' at line 1 12 mysql> delimiter $ 13 create PROCEDURE myp9(inout a int,inout b int) 14 begin 15 set a=a*2; 16 set b=b*2; 17 end $ 18 Query OK, 0 rows affected (0.00 sec) 19 20 mysql> set @a=10$ 21 Query OK, 0 rows affected (0.00 sec) 22 23 mysql> set @b=20$ 24 Query OK, 0 rows affected (0.00 sec) 25 26 mysql> call myp9(@a,@b)$ 27 Query OK, 0 rows affected (0.00 sec) 28 29 mysql> select @a,@b$ 30 +----+----+ 31 | @a | @b | 32 +----+----+ 33 | 20 | 40 | 34 +----+----+ 35 1 row in set (0.06 sec) 36 37 mysql>