列出MariaDB中所有函数的2种方法
下面是在 MariaDB 中返回函数列表的两个选项。
命令SHOW FUNCTION STATUS
列出所有函数的最快方法是使用命令。SHOW FUNCTION STATUS
只需运行以下命令即可列出所有功能:
SHOW FUNCTION STATUS;
语法是这样的:
SHOW FUNCTION STATUS
[LIKE 'pattern' | WHERE expr]
因此,您可以使用aorclause来缩小结果范围。LIKE``WHERE
例:
SHOW FUNCTION STATUS LIKE '%customer%';
示例结果:
+——–+—————————-+———-+——————+———————+———————+—————+———+———————-+———————-+——————–+ | Db | Name | Type | Definer | Modified | Created | Security_type | Comment | character_set_client | collation_connection | Database Collation | +——–+—————————-+———-+——————+———————+———————+—————+———+———————-+———————-+——————–+ | sakila | get_customer_balance | FUNCTION | barney@localhost | 2021-11-13 07:26:47 | 2021-11-13 07:26:47 | DEFINER | | utf8mb4 | utf8mb4_general_ci | utf8mb4_general_ci | | sakila | inventory_held_by_customer | FUNCTION | barney@localhost | 2021-11-13 07:26:47 | 2021-11-13 07:26:47 | DEFINER | | utf8mb4 | utf8mb4_general_ci | utf8mb4_general_ci | +——–+—————————-+———-+——————+———————+———————+—————+———+———————-+———————-+——————–+
我们可以使用子句按列过滤结果。例如,我们可以将结果过滤到给定的数据库中:WHERE
SHOW FUNCTION STATUS WHERE db = 'music';
示例结果:
+——-+——+———-+——————+———————+———————+—————+———+———————-+———————-+——————–+ | Db | Name | Type | Definer | Modified | Created | Security_type | Comment | character_set_client | collation_connection | Database Collation | +——-+——+———-+——————+———————+———————+—————+———+———————-+———————-+——————–+ | music | test | FUNCTION | barney@localhost | 2021-11-27 09:46:25 | 2021-11-27 09:46:25 | DEFINER | | utf8 | utf8_general_ci | utf8mb4_general_ci | +——-+——+———-+——————+———————+———————+—————+———+———————-+———————-+——————–+
该命令的工作方式与返回存储过程列表的命令非常相似。SHOW FUNCTION STATUS``SHOW PROCEDURE STATUS
该表information_schema.routines
在MariaDB中获取函数列表的另一种方法是查询table。information_schema.routines
例:
SELECT
routine_schema as "Database",
routine_name
FROM
information_schema.routines
WHERE
routine_type = 'FUNCTION'
ORDER BY
routine_schema ASC,
routine_name ASC;
示例结果:
+———-+—————————-+ | Database | routine_name | +———-+—————————-+ | music | test | | sakila | get_customer_balance | | sakila | inventory_held_by_customer | | sakila | inventory_in_stock | +———-+—————————-+
此表还存储有关存储过程的信息。在上面的例子中,我通过使用 aclause 只返回函数(即带有 aof 的对象)来排除它们。WHERE``routine_type``FUNCTION
要包含存储过程,我们可以删除子句:WHERE
SELECT
routine_schema as "Database",
routine_name,
routine_type
FROM
information_schema.routines
ORDER BY
routine_schema ASC,
routine_name ASC;
在本例中,我还添加了列,以便我们可以区分过程和函数。routine_type
我们还可以将其缩小到特定的数据库:
SELECT
routine_schema as "Database",
routine_name,
routine_type
FROM
information_schema.routines
WHERE
routine_schema = 'sakila'
ORDER BY
routine_name ASC;
输出:
+----------+----------------------------+--------------+
| Database | routine_name | routine_type |
+----------+----------------------------+--------------+
| sakila | film_in_stock | PROCEDURE |
| sakila | film_not_in_stock | PROCEDURE |
| sakila | get_customer_balance | FUNCTION |
| sakila | inventory_held_by_customer | FUNCTION |
| sakila | inventory_in_stock | FUNCTION |
| sakila | rewards_report | PROCEDURE |
+----------+----------------------------+--------------+