在 MySQL 中查看存储过程/函数定义?
若要查看 MySQL 中的存储过程/函数定义,可以使用 show 命令。语法如下所示:
SHOW CREATE PROCEDURE yourProcedureName;
要理解以上语法,可以创建一个过程然后查看着定义。让我们创建一个存储过程:
mysql> delimiter // mysql> create procedure AllRecords() -> begin -> select *from student; -> end // Query OK, 0 rows affected (0.24 sec)
可以使用 call 命令调用存储过程。查询如下所示:
mysql> delimiter ; mysql> call AllRecords();
输出如下所示:
+------+-------+ | id | Name | +------+-------+ | 1 | John | | 2 | Bob | | 3 | Smith | | 6 | John | +------+-------+ 4 rows in set (0.14 sec) Query OK, 0 rows affected (0.18 sec)
现在可以借助我们一开始讨论的上述语法检查定义。查询如下所示:
mysql> show create procedure AllRecords;
输出如下所示:
+------------+--------------------------------------------+-----------------------------------------------------------------------+----------------------+----------------------+--------------------+ | Procedure | sql_mode | Create Procedure | character_set_client | collation_connection | Database Collation | +------------+--------------------------------------------+-----------------------------------------------------------------------+----------------------+----------------------+--------------------+ | AllRecords | STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION | CREATE DEFINER=`root`@`%` PROCEDURE `AllRecords`() begin select *from student;end | utf8 | utf8_general_ci | utf8mb4_unicode_ci | +------------+--------------------------------------------+-----------------------------------------------------------------------+----------------------+----------------------+--------------------+ 1 row in set (0.00 sec)
要检查 MySQL 中的函数定义,可以使用 function 代替 procedure。语法如下所示:-
SHOW CREATE FUNCTION yourFunctionName;
广告