
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
How to check whether a stored procedure exist in MySQL?
Let us first create a stored procedure −
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 ;
Now you check whether the stored procedure exists with the help SHOW CREATE command.
The query is as follows −
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 the stored procedure with the help of the CALL command. The query is as follows −
mysql> call ExtenddatesWithMonthdemo('2019-02-13',6);
Output
+---------------------+ | ExtendDate | +---------------------+ | 2019-08-13 00:00:00 | +---------------------+ 1 row in set (0.10 sec) Query OK, 0 rows affected (0.12 sec)
- Related Articles
- How can a MySQL stored procedure call another MySQL stored procedure inside it?
- How to loop thrugh a stored procedure in MySQL?
- Check for NULL or empty variable in a MySQL stored procedure
- How to suppress MySQL stored procedure output?
- How to correctly use DELIMITER in a MySQL stored procedure?
- MySQL Stored Procedure to create a table?
- How to use FOR LOOP in MySQL Stored Procedure?
- How to correctly implement conditions in MySQL stored procedure?
- How can we alter a MySQL stored procedure?
- How can we drop a MySQL stored procedure?
- How to quit/ exit from MySQL stored procedure?
- Set conditions in a MySQL stored procedure
- How to call a stored procedure using select statement in MySQL?
- MySQL stored procedure to return a column value?
- How can we invoke MySQL stored procedure?

Advertisements