如何检查 MySQL 中是否存在存储过程?


首先创建存储过程 -

mysql> DELIMITER //
mysql> CREATE PROCEDURE ExtenddatesWithMonthdemo(IN date1 datetime, IN NumberOfMonth int )
   -> BEGIN
   -> SELECT DATE_ADD(date1,INTERVAL NumberOfMonth MONTH) AS ExtendDate;
   -> END;
   -> //
Query OK, 0 rows affected (0.20 sec)
mysql> DELIMITER ;

现在,您可以借助 SHOW CREATE 命令检查存储过程是否存在。

查询如下 -

mysql> SHOW CREATE PROCEDURE ExtenddatesWithMonthdemo;
The following is the output displaying the details of the stored procedure we created above:
+--------------------------+--------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+--------------------+
| Procedure                | sql_mode                                   | Create Procedure                                                                                                                        | character_set_client | collation_connection | Database Collation |
+--------------------------+--------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+--------------------+
| ExtenddatesWithMonthdemo | STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION | CREATE DEFINER = `root`@`%` PROCEDURE `ExtenddatesWithMonthdemo`(IN date1 datetime, IN NumberOfMonth int )
BEGIN
SELECT DATE_ADD(date1,INTERVAL NumberOfMonth MONTH) AS ExtendDate;
END | utf8 | utf8_general_ci | utf8_general_ci |
+--------------------------+--------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+--------------------+
1 row in set (0.00 sec)

使用 CALL 命令调用存储过程。查询如下 -

mysql> call ExtenddatesWithMonthdemo('2019-02-13',6);

输出

+---------------------+
| ExtendDate          |
+---------------------+
| 2019-08-13 00:00:00 |
+---------------------+
1 row in set (0.10 sec)
Query OK, 0 rows affected (0.12 sec)

更新日期: 30-Jul-2019

601 浏览次数

开启你的 职业

完成课程即可获得认证

开始
广告