MySQL stored procedure in, out and inout parameter examples and summary

MySQL stored procedure in, out and inout parameter examples and summary

Stored Procedures

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; //Set global variablesmysql> 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);

Summary 1:

  • in and inout parameters pass the value of the global variable into the stored procedure, while out parameters do 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 change.

2. Changes in global variable values ​​when calling a stored procedure

mysql> select @num1,@num2,@num3;

Summary 2:

  • After calling the stored procedure, it is found that the in parameter will not change the value of the global variable, while the out and inout parameters will change the value of the global variable after calling the stored procedure, and the value after the stored procedure reference will be 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.

This is the end of this article about MySQL stored procedure in, out, and inout parameter examples and summary. For more information about MySQL stored procedure in, out, and inout parameters, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Detailed explanation of creating, calling and managing MySQL stored procedures
  • Introduction to query commands for MySQL stored procedures
  • Detailed steps to modify MySQL stored procedures
  • Using cursor loop to read temporary table in Mysql stored procedure
  • Mysql modify stored procedure related permissions issue
  • In-depth explanation of MySQL stored procedures (in, out, inout)
  • How to create a table by month in MySQL stored procedure
  • A brief discussion on MySql views, triggers and stored procedures
  • Detailed example of using if statement in mysql stored procedure
  • Analysis of the advantages and disadvantages of MySQL stored procedures

<<:  Implementation of Docker private library

>>:  HTML table markup tutorial (22): row border color attribute BORDERCOLORLIGHT

Recommend

How to add Tomcat Server configuration to Eclipse

1. Window -> preferences to open the eclipse p...

How to handle MySQL numeric type overflow

Now, let me ask you a question. What happens when...

A brief discussion on Linux signal mechanism

Table of contents 1. Signal List 1.1. Real-time s...

How to define data examples in Vue

Preface In the development process, defining vari...

Detailed explanation of Nginx process scheduling problem

Nginx uses a fixed number of multi-process models...

Axios cancel request and avoid duplicate requests

Table of contents origin status quo Cancel reques...

Thoughts on copy_{to, from}_user() in the Linux kernel

Table of contents 1. What is copy_{to,from}_user(...

How to set an alias for a custom path in Vue

How to configure custom path aliases in Vue In ou...

HTML elements (tags) and their usage

a : Indicates the starting or destination positio...

Analysis of MySQL duplicate index and redundant index examples

This article uses examples to describe MySQL dupl...

How to use Linux paste command

01. Command Overview The paste command will merge...

JavaScript+html to implement front-end page sliding verification (2)

This article example shares the specific code of ...

CentOS 6 uses Docker to deploy redis master-slave database operation example

This article describes how to use docker to deplo...