Preliminary study of mysql stored procedure

Recently, the MySQL database will be used, so I will record the learning process.
MySQL 5.0 and later versions begin to support stored procedures. Stored procedures have the characteristics of consistency, efficiency, security, and architecture. We will explain how to manipulate MySQL stored procedures through specific examples.
1. Create a stored procedure
A semicolon needs to be used in a stored procedure, so before creating a stored procedure, you must use the delimiter command to change the terminator,
MySQL>delimiter // (This command means to change the original terminator; to //As a terminator)
and then use create procedure to create a stored procedure, the following is an inserted column
MySQL>create procedure ins_proc(in para1 varchar(20),in para2 varchar(20))
MySQL>begin
MySQL>insert into t( name,owner)values(para1,para2);
MySQL>end;//
Explanation:
in para1 varchar(20)----in means input parameter, para1--parameter name, varchar(20)--parameter type
in --indicates input, out--indicates output, inout--indicates input and output



2. Call the stored procedure
call using the call command,
MySQL>call ins_proc('author','pwd');//The ins_proc stored procedure will be called, and Taking author and pwd as input parameters, will be inserted in the t table.
If it is a program call, just write the sql statement as "call ins_proc('author','pwd');", and then execute the sql statement.


3. View the stored procedure
Use the command show,
MySQL>show procedure status;//You can view all procedures



4. Delete the stored procedure
Use the command drop,
MySQL>drop ins_proc;//Delete ins_proc

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326484984&siteId=291194637