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

Tips for List Building for Website Maintenance Pages

And, many times, maintenance requires your website...

MySQL data type details

Table of contents 1. Numeric Type 1.1 Classificat...

Detailed steps to install docker in 5 minutes

Installing Docker on CentOS requires the operatin...

Comprehensive website assessment solution

<br />Sometimes you may be asked questions l...

Deploy the Vue project on a Linux server

Case 1 vue-cli builds the vue3 project, uploads t...

Vue Beginner's Guide: Creating the First Vue-cli Scaffolding Program

1. Vue--The first vue-cli program The development...

Detailed tutorial on installing Docker on CentOS 8

1. Previous versions yum remove docker docker-cli...

Initial settings after installing Ubuntu 16 in the development environment

The office needs Ubuntu system as the Linux devel...

Docker builds cluster MongoDB implementation steps

Preface Due to the needs of the company's bus...

Installation and configuration method of Zabbix Agent on Linux platform

Here is a brief summary of the installation and c...

Method of Vue component document generation tool library

Table of contents Parsing .vue files Extract docu...