Nedenfor er to muligheder for at returnere en liste over funktioner i MariaDB.
SHOW FUNCTION STATUS
Kommando
Den hurtigste måde at få vist alle funktioner på er at bruge SHOW FUNCTION STATUS
kommando.
Kør blot følgende for at få en liste over alle funktioner:
SHOW FUNCTION STATUS;
Syntaksen ser sådan ud:
SHOW FUNCTION STATUS
[LIKE 'pattern' | WHERE expr]
Så du kan bruge en LIKE
eller WHERE
klausul for at indsnævre resultaterne.
Eksempel:
SHOW FUNCTION STATUS LIKE '%customer%';
Eksempelresultat:
+--------+----------------------------+----------+------------------+---------------------+---------------------+---------------+---------+----------------------+----------------------+--------------------+ | Db | Name | Type | Definer | Modified | Created | Security_type | Comment | character_set_client | collation_connection | Database Collation | +--------+----------------------------+----------+------------------+---------------------+---------------------+---------------+---------+----------------------+----------------------+--------------------+ | sakila | get_customer_balance | FUNCTION | [email protected] | 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 | [email protected] | 2021-11-13 07:26:47 | 2021-11-13 07:26:47 | DEFINER | | utf8mb4 | utf8mb4_general_ci | utf8mb4_general_ci | +--------+----------------------------+----------+------------------+---------------------+---------------------+---------------+---------+----------------------+----------------------+--------------------+
Vi kan bruge WHERE
klausul for at filtrere resultaterne efter kolonnerne. For eksempel kan vi filtrere resultaterne til en given database:
SHOW FUNCTION STATUS WHERE db = 'music';
Eksempelresultat:
+-------+------+----------+------------------+---------------------+---------------------+---------------+---------+----------------------+----------------------+--------------------+ | Db | Name | Type | Definer | Modified | Created | Security_type | Comment | character_set_client | collation_connection | Database Collation | +-------+------+----------+------------------+---------------------+---------------------+---------------+---------+----------------------+----------------------+--------------------+ | music | test | FUNCTION | [email protected] | 2021-11-27 09:46:25 | 2021-11-27 09:46:25 | DEFINER | | utf8 | utf8_general_ci | utf8mb4_general_ci | +-------+------+----------+------------------+---------------------+---------------------+---------------+---------+----------------------+----------------------+--------------------+
SHOW FUNCTION STATUS
kommandoen fungerer meget som SHOW PROCEDURE STATUS
kommando, som returnerer en liste over lagrede procedurer.
information_schema.routines
Tabel
En anden måde at få en liste over funktioner i MariaDB på er at forespørge information_schema.routines
tabel.
Eksempel:
SELECT
routine_schema as "Database",
routine_name
FROM
information_schema.routines
WHERE
routine_type = 'FUNCTION'
ORDER BY
routine_schema ASC,
routine_name ASC;
Eksempelresultat:
+----------+----------------------------+ | Database | routine_name | +----------+----------------------------+ | music | test | | sakila | get_customer_balance | | sakila | inventory_held_by_customer | | sakila | inventory_in_stock | +----------+----------------------------+
Denne tabel gemmer også oplysninger om lagrede procedurer. I ovenstående eksempel ekskluderede jeg dem ved at bruge en WHERE
klausul for kun at returnere funktioner (dvs. objekter med en routine_type
af FUNCTION
).
For at inkludere lagrede procedurer kan vi fjerne WHERE
klausul:
SELECT
routine_schema as "Database",
routine_name,
routine_type
FROM
information_schema.routines
ORDER BY
routine_schema ASC,
routine_name ASC;
I dette tilfælde tilføjede jeg også routine_type
kolonne, så vi kan skelne mellem procedurerne og funktionerne.
Vi kan også indsnævre det til en bestemt database:
SELECT
routine_schema as "Database",
routine_name,
routine_type
FROM
information_schema.routines
WHERE
routine_schema = 'sakila'
ORDER BY
routine_name ASC;
Resultat:
+----------+----------------------------+--------------+ | 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 | +----------+----------------------------+--------------+