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

让我们首先创建一个存储过程-

mysql> DELIMITER //
mysql> CREATE PROCEDURE ExtenddatesWithMonthdemo(IN date1 datetime, IN NumberOfMonth int )
   -> BEGIN
   -> SELECT DATE_ADD(date1,INTERVAL NumberOfMonth MONTH) AS ExtendDate;
   -> END;
   -> //
mysql> DELIMITER ;

现在,使用help 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)