13.7.7.9 SHOW CREATE PROCEDURE Statement语句

SHOW CREATE PROCEDURE proc_name

This statement is a MySQL extension. 此语句是MySQL扩展。It returns the exact string that can be used to re-create the named stored procedure. 它返回可用于重新创建命名存储过程的确切字符串。A similar statement, SHOW CREATE FUNCTION, displays information about stored functions (see Section 13.7.7.8, “SHOW CREATE FUNCTION Statement”).类似的语句SHOW CREATE FUNCTION显示有关存储函数的信息(请参阅第13.7.7.8节,“SHOW CREATE FUNCTION语句”)。

To use either statement, you must be the user named as the routine DEFINER, have the SHOW_ROUTINE privilege, have the SELECT privilege at the global level, or have the CREATE ROUTINE, ALTER ROUTINE, or EXECUTE privilege granted at a scope that includes the routine. 要使用任一语句,您必须是名为例程DEFINER的用户,具有CREATE ROUTINE权限,在全局级别具有SELECT权限,或者在包含例程的范围内授予CREATE ROUTINEALTER ROUTINEEXECUTE权限。The value displayed for the Create Procedure or Create Function field is NULL if you have only CREATE ROUTINE, ALTER ROUTINE, or EXECUTE.如果只有Create ProcedureALTER ProcedureEXECUTE,则Create ProcedureCreate Function字段显示的值为NULL

mysql> SHOW CREATE PROCEDURE test.citycount\G
*************************** 1. row ***************************
           Procedure: citycount
            sql_mode: ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,
                      NO_ZERO_IN_DATE,NO_ZERO_DATE,
                      ERROR_FOR_DIVISION_BY_ZERO,
                      NO_ENGINE_SUBSTITUTION
    Create Procedure: CREATE DEFINER=`me`@`localhost`
                      PROCEDURE `citycount`(IN country CHAR(3), OUT cities INT)
                      BEGIN
                        SELECT COUNT(*) INTO cities FROM world.city
                        WHERE CountryCode = country;
                      END
character_set_client: utf8mb4
collation_connection: utf8mb4_0900_ai_ci
  Database Collation: utf8mb4_0900_ai_ci

mysql> SHOW CREATE FUNCTION test.hello\G
*************************** 1. row ***************************
            Function: hello
            sql_mode: ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,
                      NO_ZERO_IN_DATE,NO_ZERO_DATE,
                      ERROR_FOR_DIVISION_BY_ZERO,
                      NO_ENGINE_SUBSTITUTION
     Create Function: CREATE DEFINER=`me`@`localhost`
                      FUNCTION `hello`(s CHAR(20))
                      RETURNS char(50) CHARSET utf8mb4
                      DETERMINISTIC
                      RETURN CONCAT('Hello, ',s,'!')
character_set_client: utf8mb4
collation_connection: utf8mb4_0900_ai_ci
  Database Collation: utf8mb4_0900_ai_ci

character_set_client is the session value of the character_set_client system variable when the routine was created. character_set_client是创建例程时character_set_client系统变量的会话值。collation_connection is the session value of the collation_connection system variable when the routine was created. collation_connection是创建例程时collation_connection系统变量的会话值。Database Collation is the collation of the database with which the routine is associated.Database Collation是与例程关联的数据库的排序规则。