使用 INT 和 VARCHAR 值呼叫 MySQL 儲存過程


要呼叫儲存過程,可以使用 CALL 命令。以下是語法 −

CALL yourStoredProcedureName(parameter if any);

讓我們首先建立一個示例過程。以下是要建立儲存過程的查詢。這裡,我們設定了兩個值,一個是 INT,另一個是 VARCHAR −

mysql> DELIMITER //
mysql> CREATE PROCEDURE CALL_PROC(Id int,Name varchar(40))
   BEGIN
   SELECT CONCAT('You have entered the Id which is=',Id);
   SELECT CONCAT('You have entered the Name which is=',Name);
   END
//
Query OK, 0 rows affected (0.21 sec)
mysql> DELIMITER ;

以下是用於呼叫 MySQL 中的儲存過程的查詢 −

mysql> CALL CALL_PROC(1001,'Chris');

這將生成以下輸出 −

+------------------------------------------------+
| CONCAT('You have entered the Id which is=',Id) |
+------------------------------------------------+
| You have entered the Id which is=1001          |
+------------------------------------------------+
1 row in set (0.00 sec)
+----------------------------------------------------+
| CONCAT('You have entered the Name which is=',Name) |
+----------------------------------------------------+
| You have entered the Name which is=Chris           |
+----------------------------------------------------+
1 row in set (0.02 sec)
Query OK, 0 rows affected, 1 warning (0.04 sec)

更新日期: 2019-10-04

971 次瀏覽

啟動您的 職業

透過完成課程獲得認證

開始
廣告
© . All rights reserved.