Two ways to write stored procedures in Mysql with and without return values

Two ways to write stored procedures in Mysql with and without return values

Process 1: with return value:

 drop procedure if exists proc_addNum;
 create procedure proc_addNum (in x int, in y int, out sum int)
 BEGIN
 SET sum = x + y;
 end

Then, execute the process and output the return value:

 call proc_addNum(2,3,@sum);
select @sum;

Procedure 2: Without return value:

 drop procedure if exists proc_addNum;
 create procedure proc_addNum (in x int, in y int)
 BEGIN
 DECLARE sum int;
 SET sum = x + y;
 SELECT sum;
 end

Execution process:

 call proc_addNum(2,3);

Summarize

The above is the two ways of writing MySQL stored procedures with and without return values ​​that I introduced to you. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time!

You may also be interested in:
  • Simple writing of MYSQL stored procedures and functions
  • Detailed example of MySQL data storage process parameters
  • Detailed explanation of MySQL stored procedures, cursors, and transaction examples
  • How to create a stored procedure in MySQL and add records in a loop
  • Detailed explanation of the entry-level use of MySql stored procedure parameters
  • mysql uses stored procedures to implement tree node acquisition method

<<:  Detailed steps for building, running, publishing, and obtaining a Docker image for the first time

>>:  Steps for Docker to build its own local image repository

Recommend

The difference between Div and table in HTML (discussed in detail in all aspects)

1: Differences in speed and loading methods The di...

CSS animation property usage and example code (transition/transform/animation)

During development, a good user interface will al...

How to use provide to implement state management in Vue3

Table of contents Preface How to implement Vuex f...

React Hooks Usage Examples

Table of contents A simple component example More...

What is this in JavaScript point by point series

Understand this Perhaps you have seen this in oth...

The combination and difference between ENTRYPOINT and CMD in dockerfile

In the previous article [Detailed explanation of ...

Using Docker Enterprise Edition to build your own private registry server

Docker is really cool, especially because it'...

Detailed tutorial on building a local idea activation server

Preface The blogger uses the idea IDE. Because th...

A brief analysis of how to set the initial value of Linux root

Ubuntu does not allow root login by default, so t...

HTML table markup tutorial (16): title horizontal alignment attribute ALIGN

By default, the table title is horizontally cente...

Detailed Analysis of the Differences between break and last in Nginx

Let's talk about the difference first last, t...

Quick solution for forgetting MySQL8 password

Preface When we forget the MySQL database passwor...

How to set up virtual directories and configure virtual paths in Tomcat 7.0

Tomcat7.0 sets virtual directory (1) Currently, o...