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

MySQL 8.0.11 installation summary tutorial diagram

Installation environment: CAT /etc/os-release Vie...

Viewing and analyzing MySQL execution status

When you feel that there is a problem with MySQL ...

js dynamically adds example code for a list of circled numbers

1. Add the ul tag in the body first <!-- Unord...

Vue.js implements simple folding panel

This article example shares the specific code of ...

MySql multi-condition query statement with OR keyword

The previous article introduced the MySql multi-c...

JS ES new features template string

Table of contents 1. What is a template string? 2...

Installation process of zabbix-agent on Kylin V10

1. Download the installation package Download add...

Mysql specifies the date range extraction method

In the process of database operation, it is inevi...

Example code for implementing stacked carousel effect with HTML+CSS+JS

Effect: When the slideshow moves in one direction...

Native js drag and drop function to create a slider example code

Drag and drop is a common function in the front e...

MySQL 5.7.18 Green Edition Download and Installation Tutorial

This article records the detailed process of down...

How to create a web wireframe using Photoshop

This post introduces a set of free Photoshop wire...

Installation and use tutorial of Elasticsearch tool cerebro

Cerebro is an evolution of the Elasticsearch Kopf...

Detailed explanation of using Nginx reverse proxy to solve cross-domain problems

question In the previous article about cross-doma...