MySQL 8.4 Release Notes
15.7.7.10 显示创建存储过程语句
SHOW CREATE PROCEDURE proc_name
这是MySQL的扩展语句。它返回用于重新创建命名存储过程的exact字符串。类似语句SHOW CREATE FUNCTION
显示关于存储函数的信息(见第15.7.7.9节,“SHOW CREATE FUNCTION Statement”).
要使用任何语句,您必须是命名存储过程的用户DEFINER
,拥有SHOW_ROUTINE
权限,拥有SELECT
权限在全局级别,或者拥有CREATE ROUTINE
、ALTER ROUTINE
或EXECUTE
权限在包含存储过程的范围内。显示的Create Procedure
或Create Function
字段的值为NULL
如果您只有CREATE ROUTINE
、ALTER ROUTINE
或EXECUTE
权限。
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
是存储过程创建时的character_set_client
系统变量的会话值。collation_connection
是存储过程创建时的collation_connection
系统变量的会话值。Database Collation
是与存储过程关联的数据库的排序规则。