如何建立帶有 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 千次瀏覽

開啟你的職業生涯

完成課程獲得認證

入門
廣告
© . All rights reserved.