要在MySQL中查看存储过程/函数定义,可以使用show命令。语法如下-
SHOW CREATE PROCEDURE yourProcedureName;
要了解上述语法,您可以创建一个过程并检查该定义。让我们创建一个存储过程-
mysql> delimiter // mysql> create procedure AllRecords() -> begin -> select *from student; -> end //
您可以在call命令的帮助下调用存储过程。查询如下-
mysql> delimiter ; mysql> call AllRecords();
以下是输出-
+------+-------+ | id | Name | +------+-------+ | 1 | John | | 2 | Bob | | 3 | Smith | | 6 | John | +------+-------+ 4 rows in set (0.14 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中的函数定义,可以使用函数代替过程。语法如下:-
SHOW CREATE FUNCTION yourFunctionName;