建立:delimiter // create procedure my_add(IN a int, IN b int, OUT c int) begin if a is null then set a = 0; end if; if b is null then set b = 0; end if; set c = a + b; end;//delimiter ;檢視:方法一:(直接查詢,比較實用,檢視當前自定義的儲存過程)select `specific_name` from mysql.proc where `db` = "your_db_name" and `type` = "procedure"方法二:(檢視資料庫裡所有儲存過程+內容)show procedure status;方法三:(檢視當前資料庫裡儲存過程列表)select specific_name from mysql.proc ;方法四:(檢視某一個儲存過程的具體內容)select body from mysql.proc where specific_name = "your_proc_name";檢視儲存過程或函式的建立程式碼 :show create procedure your_proc_name;show create function your_func_name;呼叫:mysql> set @a = 10;Query OK, 0 rows affected (0.00 sec)mysql> set @b = 20;Query OK, 0 rows affected (0.00 sec)mysql> set @c = 0;Query OK, 0 rows affected (0.00 sec)mysql>select @c;+------+| @c |+------+| 0 |+------+mysql> call my_add(@a, @b, @c);Query OK, 0 rows affected (0.00 sec)mysql> select @a, @b, @c;+------+------+------+| @a | @b | @c |+------+------+------+| 10 | 20 | 30 |+------+------+------+1 row in set (0.00 sec)刪除drop procedure your_proc_name;
建立:delimiter // create procedure my_add(IN a int, IN b int, OUT c int) begin if a is null then set a = 0; end if; if b is null then set b = 0; end if; set c = a + b; end;//delimiter ;檢視:方法一:(直接查詢,比較實用,檢視當前自定義的儲存過程)select `specific_name` from mysql.proc where `db` = "your_db_name" and `type` = "procedure"方法二:(檢視資料庫裡所有儲存過程+內容)show procedure status;方法三:(檢視當前資料庫裡儲存過程列表)select specific_name from mysql.proc ;方法四:(檢視某一個儲存過程的具體內容)select body from mysql.proc where specific_name = "your_proc_name";檢視儲存過程或函式的建立程式碼 :show create procedure your_proc_name;show create function your_func_name;呼叫:mysql> set @a = 10;Query OK, 0 rows affected (0.00 sec)mysql> set @b = 20;Query OK, 0 rows affected (0.00 sec)mysql> set @c = 0;Query OK, 0 rows affected (0.00 sec)mysql>select @c;+------+| @c |+------+| 0 |+------+mysql> call my_add(@a, @b, @c);Query OK, 0 rows affected (0.00 sec)mysql> select @a, @b, @c;+------+------+------+| @a | @b | @c |+------+------+------+| 10 | 20 | 30 |+------+------+------+1 row in set (0.00 sec)刪除drop procedure your_proc_name;