The SHOW CREATE PROCEDURE statement displays information about a stored procedure.
The syntax of the SHOW CREATE PROCEDURE statement is as follows:
SHOW CREATE PROCEDURE proc_name
To use this statement, you must be the user defined by the DEFINER clause for the stored procedure, or have the global SELECT privilege. In this case, the Create Procedure (create procedure) field displays the complete definition of the stored procedure. If you only have the CREATE ROUTINE, ALTER ROUTINE, or EXECUTE privilege on the routine, or do not have any of these privileges, no error is returned during execution, but the value of the Create Procedure (create procedure) field is NULL.
The SHOW CREATE PROCEDURE statement returns the following information:
Procedure: the name of the stored procedure.sql_mode: the SQL mode in effect when the stored procedure is executed.Create Procedure: theCREATE PROCEDUREstatement that defines the stored procedure.character_set_client: the value of thecharacter_set_clientsystem variable in the current session when the stored procedure is created.collation_connection: the value of thecollation_connectionsystem variable in the current session when the stored procedure is created.Database Collation: the collation of the database associated with the stored procedure.
You can also obtain information about stored procedures from the INFORMATION_SCHEMA ROUTINES table. For more information, see INFORMATION_SCHEMA PARAMETERS.
Here is an example of the SHOW CREATE PROCEDURE statement:
obclient> SHOW CREATE PROCEDURE proc_name;
The output is as follows:
+-------------+----------+-----------------+-----------------------+----------------------+--------------------+
| Procedure | sql_mode | Create Procedure | character_set_client | collation_connection | Database Collation |
+----------+----------+-----------------+-----------------------+----------------------+-----------------------+
| proc_name | STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE |CREATE PROCEDURE `test`.`proc_name`() BEGIN DECLARE var_name VARCHAR(20) DEFAULT 'ZhangSan'; SET var_name = 'LiSi'; SELECT var_name; END | utf8mb4 | utf8mb4_general_ci | utf8mb4_general_ci |
+----------+----------+-----------------+-----------------------+----------------------+-----------------------+
1 row in set