Summary of MySQL stored procedure in, out, inout parameter examples

coldplay.xixi
Release: 2021-01-06 09:38:39
forward
2402 people have browsed it

mysql video tutorialThe column introduces the in, out, and inout parameters of MySQL stored procedures

Summary of MySQL stored procedure in, out, inout parameter examples

Recommendation (free):mysql video tutorial

Article Directory

  • Stored Procedure
    • 1. Create a stored procedure and view global variables
    • 2. Changes in global variable values when calling stored procedures

Stored Procedure

1. Create a stored procedure and view global variables

mysql> create database yy;Query OK, 1 row affected (0.00 sec)mysql> use yy;Database changed mysql> set @num1=10,@num2=20,@num3=30; //设置全局变量mysql> delimiter $$ mysql> create procedure p(in num1 int,out num2 int,inout num3 int) -> begin -> select num1,num2,num3; -> set num1=100,num2=200,num3=300; -> select num1,num2,num3; -> end $$ Query OK, 0 rows affected (0.00 sec)mysql> delimiter ;mysql> call p(@num1,@num2,@num3);
Copy after login

Summary of MySQL stored procedure in, out, inout parameter examples
Summary 1:

  • The in and inout parameters will pass the value of the global variable into the stored procedure, while the out parameter will not pass the value of the global variable into the stored procedure. When using a stored procedure, the parameter values in, out, and inout will all change.

2. Changes in global variable values when calling stored procedures

mysql> select @num1,@num2,@num3;
Copy after login

Summary of MySQL stored procedure in, out, inout parameter examples
Summary 2:

  • After calling the stored procedure, it is found that the in parameter will not change the value of the global variable, but the out and inout parameters will change the value of the global variable after calling the stored procedure, and the stored procedure will be changed. The value after the procedure reference is assigned to the global variable.
  • The in parameter assignment type can be a variable or a fixed value, while the out and inout parameter assignment types must be variables.

For more programming-related knowledge, please visit:Introduction to Programming! !

The above is the detailed content of Summary of MySQL stored procedure in, out, inout parameter examples. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!