DROP PROCEDURE IF EXISTS mycanshu
;
CREATE DEFINER = root
@localhost
PROCEDURE mycanshu
(IN num
int)
–带参数的输入 IN 输入的参数,缺省时也是。out 输出的参数。inout 可以是输入参数也可是输出参数。
BEGIN
#Routine body goes here…
DECLARE nums INT ;
SET nums= POWER(num,2); – 输入参数的平方
select nums ;
END;
运行结果:
mysql> call mycanshu(4);
+——+
| nums |
+——+
| 16 |
+——+
1 row in set
Query OK, 0 rows affected
mysql>
– 带输出参数
DROP PROCEDURE IF EXISTS myout
;
CREATE DEFINER = root
@localhost
PROCEDURE myout
(IN num
int,OUT numout
int)
BEGIN
#Routine body goes here…
SET numout=POW(num,2);
select numout ;
END;
运行结果:
mysql> call myout(3,@out
);
+——–+
| numout |
+——–+
| 9 |
+——–+
1 row in set
Query OK, 0 rows affected
mysql>