The SHOW CREATE FUNCTION statement displays information about a stored function.
Syntax
SHOW CREATE FUNCTION func_name
Parameters
Parameter |
Description |
|---|---|
| func_name | The name of the stored function to view. You can specify the database name in the format database_name.func_name. |
To execute this statement, you must be the user defined by the DEFINER clause of the stored function, or have the global SELECT privilege. In this case, the Create Function field displays the complete definition of the stored function. If you have only the CREATE ROUTINE, ALTER ROUTINE, or EXECUTE privilege on the routine, no error is returned during execution, but the value of the Create Function field is NULL. If you do not have any of the preceding privileges, an error ERROR 1305 (42000): procedure/function does not exist is returned during execution.
The SHOW CREATE FUNCTION statement outputs the following information:
Function: The name of the stored function.sql_mode: The SQL mode in effect when the stored function is executed.Create Function: TheCREATE FUNCTIONstatement used to define the stored function.character_set_client: The value of thecharacter_set_clientsystem variable in the current session when the stored function was created.collation_connection: The value of thecollation_connectionsystem variable in the current session when the stored function was created.Database Collation: The collation of the database associated with the stored function.
You can also obtain information about stored functions from the INFORMATION_SCHEMA ROUTINES table. For more information, see INFORMATION_SCHEMA PARAMETERS.
Examples
View the definition of a stored function.
obclient> DELIMITER //
obclient> CREATE FUNCTION my_func(c1 CHAR(20)) RETURNS CHAR(50) DETERMINISTIC RETURN CONCAT('Thank ', c1, '!') //
obclient> DELIMITER ;
obclient> SHOW CREATE FUNCTION my_func;
The query result is as follows:
+----------+----------+-----------------+-----------------------+----------------------+--------------------+
| Function | sql_mode | Create Function | character_set_client | collation_connection | Database Collation |
+----------+----------+-----------------+-----------------------+----------------------+--------------------+
| my_func | STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE | CREATE FUNCTION `test`.`my_func`(`c1` char(20)) RETURNS char(50) RETURN CONCAT('Thank ',c1,'!') | utf8mb4 | utf8mb4_general_ci | utf8mb4_general_ci |
+----------+----------+-----------------+-----------------------+----------------------+--------------------+
1 row in set