Home > Database > Mysql Tutorial > body text

Query mysql stored procedure

WBOY
Release: 2023-05-14 11:45:09
Original
645 people have browsed it

1. Overview

MySQL stored procedure is a very important feature in the MySQL database. It can encapsulate some SQL statements that need to be executed frequently into a unit for easy management and use. This article will introduce how to query MySQL stored procedures.

2. Basic syntax for querying stored procedures

The basic syntax for querying MySQL stored procedures is as follows:

SHOW PROCEDURE STATUS [LIKE 'pattern'];
Copy after login

pattern is the matching pattern of the procedure name , you can use the wildcard characters % and _.

3. Detailed explanation of parameters for querying stored procedures

When using the above syntax to query stored procedures, you can obtain results including the following columns:

##CommentComment of stored procedure## 4. Example
Column nameDescription
DbThe name of the database where the stored procedure is located
NameThe name of the stored procedure
TypeIf the stored procedure has input parameters or output parameters, it is PROCEDURE, otherwise it is FUNCTION
DefinerThe definer of the stored procedure
ModifiedThe last modified stored procedure Time
CreatedThe time when the stored procedure was created
Security_typeThe security type of the stored procedure : DEFINER or INVOKER

Suppose there is a stored procedure in our MySQL database named

get_total

, and the code is as follows: <div class="code" style="position:relative; padding:0px; margin:0px;"><pre class='brush:php;toolbar:false;'>CREATE PROCEDURE `get_total`(IN `p_price` INT, OUT `p_total` DECIMAL(10,2)) BEGIN SELECT SUM(price) INTO p_total FROM orders WHERE price&gt;p_price; END;</pre><div class="contentsignin">Copy after login</div></div> We can use the following statement to query the information of the stored procedure:

SHOW PROCEDURE STATUS WHERE Name='get_total';
Copy after login

The query results are as follows:

+-----------+----------+-------+---------+---------------------+---------------------+----------------+---------+
| Db        | Name     | Type  | Definer | Modified            | Created             | Security_type  | Comment |
+-----------+----------+-------+---------+---------------------+---------------------+----------------+---------+
| test_db   | get_total| PROCEDURE | root@%   | 2019-01-01 00:00:00 | 2018-01-01 00:00:00 | DEFINER        | a test  |
+-----------+----------+-------+---------+---------------------+---------------------+----------------+---------+
Copy after login

Through this result, we can obtain the relevant information of the stored procedure

get_total

, including the database test_db, and the process type is PROCEDURE. The definer is root@%, the last modification time is 2019-01-01 00:00:00, and the creation time is 2018-01-01 00:00:00 , security type is DEFINER and annotation is a test. 5. Summary

Through the above examples, we can see that querying MySQL stored procedures is very simple. You only need to use the SHOW PROCEDURE STATUS statement. Through query, we can obtain the relevant information of the stored procedure, which facilitates further management and use of the stored procedure. In practical applications, stored procedures are one of the indispensable and important features of the MySQL database. It can greatly improve the efficiency and security of database operations, allowing developers to focus more on the implementation of business logic.

The above is the detailed content of Query mysql stored procedure. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template