I MariaDB kan vi använda SHOW PROCEDURE STATUS
kommando för att returnera en lista över lagrade procedurer.
Vi kan också fråga information_schema.routines
tabell för att göra samma sak.
SHOW PROCEDURE STATUS
Kommando
Det enklaste sättet att lista ut alla lagrade procedurer är att använda SHOW PROCEDURE STATUS
kommando.
Kör helt enkelt följande för att lista alla lagrade procedurer:
SHOW PROCEDURE STATUS;
Syntaxen ser ut så här:
SHOW PROCEDURE STATUS
[LIKE 'pattern' | WHERE expr]
Så du kan använda en LIKE
sats eller WHERE
klausul för att begränsa resultaten.
Exempel:
SHOW PROCEDURE STATUS LIKE 'film%';
Resultat:
+--------+-------------------+-----------+------------------+---------------------+---------------------+---------------+---------+----------------------+----------------------+--------------------+ | Db | Name | Type | Definer | Modified | Created | Security_type | Comment | character_set_client | collation_connection | Database Collation | +--------+-------------------+-----------+------------------+---------------------+---------------------+---------------+---------+----------------------+----------------------+--------------------+ | sakila | film_in_stock | PROCEDURE | [email protected] | 2021-11-13 07:26:47 | 2021-11-13 07:26:47 | DEFINER | | utf8mb4 | utf8mb4_general_ci | utf8mb4_general_ci | | sakila | film_not_in_stock | PROCEDURE | [email protected] | 2021-11-13 07:26:47 | 2021-11-13 07:26:47 | DEFINER | | utf8mb4 | utf8mb4_general_ci | utf8mb4_general_ci | +--------+-------------------+-----------+------------------+---------------------+---------------------+---------------+---------+----------------------+----------------------+--------------------+
information_schema.routines
Tabell
Ett annat sätt att få en lista över lagrade procedurer är att fråga information_schema.routines
bord.
Exempel:
SELECT
routine_schema as "Database",
routine_name
FROM
information_schema.routines
WHERE
routine_type = 'PROCEDURE'
ORDER BY
routine_schema ASC,
routine_name ASC;
Resultat:
+----------+--------------------+ | Database | routine_name | +----------+--------------------+ | mysql | AddGeometryColumn | | mysql | DropGeometryColumn | | pethouse | spGetAllPets | | pethouse | spGetPetById | | sakila | film_in_stock | | sakila | film_not_in_stock | | sakila | rewards_report | +----------+--------------------+
Den här tabellen lagrar även information om lagrade funktioner. I exemplet ovan uteslöt jag dessa genom att använda en WHERE
sats för att endast returnera lagrade procedurer (d.v.s. objekt med en routine_type
av PROCEDURE
).
För att inkludera lagrade funktioner kan vi ta bort WHERE
klausul:
SELECT
routine_schema as "Database",
routine_name,
routine_type
FROM
information_schema.routines
ORDER BY
routine_schema ASC,
routine_name ASC;
Resultat:
+----------+----------------------------+--------------+ | Database | routine_name | routine_type | +----------+----------------------------+--------------+ | mysql | AddGeometryColumn | PROCEDURE | | mysql | DropGeometryColumn | PROCEDURE | | pethouse | spGetAllPets | PROCEDURE | | pethouse | spGetPetById | PROCEDURE | | 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 | +----------+----------------------------+--------------+
I det här fallet lade jag också till routine_type
kolumn så att vi kan skilja mellan procedurerna och funktionerna.
Vi kan också exkludera vissa databaser från resultatet om vi vill:
SELECT
routine_schema as "Database",
routine_name,
routine_type
FROM
information_schema.routines
WHERE
routine_schema NOT IN ('sys', 'information_schema', 'mysql', 'performance_schema')
ORDER BY
routine_schema ASC,
routine_name ASC;
Resultat:
+----------+----------------------------+--------------+ | Database | routine_name | routine_type | +----------+----------------------------+--------------+ | pethouse | spGetAllPets | PROCEDURE | | pethouse | spGetPetById | PROCEDURE | | 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 | +----------+----------------------------+--------------+
Eller så kan vi begränsa det till en given databas:
SELECT
routine_schema as "Database",
routine_name,
routine_type
FROM
information_schema.routines
WHERE
routine_schema = 'pethouse'
ORDER BY
routine_name ASC;
Resultat:
+----------+--------------+--------------+ | Database | routine_name | routine_type | +----------+--------------+--------------+ | pethouse | spGetAllPets | PROCEDURE | | pethouse | spGetPetById | PROCEDURE | +----------+--------------+--------------+