如何创建带有 INOUT 参数的 MySQL 存储过程?


以下示例将演示 MySQL 存储过程与 INOUT 参数 −

mysql> DELIMITER // ;
mysql> Create PROCEDURE counter(INOUT count INT, IN increment INT)
    -> BEGIN
    -> SET count = count + increment;
    -> END //
Query OK, 0 rows affected (0.03 sec)

此处,‘count’是 INOUT 参数,它可以存储和返回值,而‘increment’是 IN 参数,它接受用户输入的值。

mysql> DELIMITER ;
mysql> SET @counter = 0;
Query OK, 0 rows affected (0.00 sec)

mysql> CALL counter(@Counter, 1);
Query OK, 0 rows affected (0.00 sec)

mysql> Select @Counter;
+----------+
| @Counter |
+----------+
| 1        |
+----------+
1 row in set (0.00 sec)

mysql> CALL counter(@Counter, 5);
Query OK, 0 rows affected (0.00 sec)

mysql> Select @Counter;
+----------+
| @Counter |
+----------+
| 6        |
+----------+
1 row in set (0.00 sec)

更新于:22-06-2020

1 千次浏览

开启你的职业生涯

完成课程获得认证

入门
广告