1. 程式人生 > 實用技巧 >MySQL教程107-MySQL呼叫儲存過程

MySQL教程107-MySQL呼叫儲存過程

呼叫儲存過程:

call sp_name[(傳參)];

例項1 呼叫儲存過程 GetAgeByStu, 接收輸入引數stu_name, 如下:

先檢視儲存過程 GetAgeByStu 的建立sql

mysql> show create procedure GetAgeByStu\G;
*************************** 1. row ***************************
           Procedure: GetAgeByStu
            sql_mode: ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
    
Create Procedure: CREATE DEFINER=`root`@`%` PROCEDURE `GetAgeByStu`(in stu_name varchar(25)) begin select age from tb_student_info where name=stu_name; end character_set_client: utf8mb4 collation_connection: utf8mb4_0900_ai_ci Database Collation: utf8_general_ci 1 row in set (0.00 sec)

執行呼叫.

mysql>
call GetAgeByStu('Tom'); +------+ | age | +------+ | 23 | +------+ 1 row in set (0.00 sec) Query OK, 0 rows affected (0.01 sec)

其他更詳細深入的關於儲存過程的學習, 可以參考這裡 -> 儲存過程