Detailed explanation of the entry-level use of MySql stored procedure parameters

Detailed explanation of the entry-level use of MySql stored procedure parameters

Use of stored procedure in parameters

IN parameters are only used to pass information to the procedure and have default values.

-- Usage of in parameters in stored procedures DELIMITER ;; 
CREATE PROCEDURE 
name_in(IN `time` VARCHAR(50)) 
BEGIN
 
 
SELECT NOW() ,`time`;
 
END ;;
CALL name_in('now time'); -- in is a formal parameter. You can define the data type and give the actual parameter DELIMITER when calling the stored procedure;; 
CREATE PROCEDURE name_in_2(IN `time` VARCHAR(50)) -- Use BEGIN for set assignment
 
 
SELECT NOW() ,`time`;
 
END ;;
SET @wo='now time'; 
CALL name_in_2(@wo);
 
DELIMITER ;; 
CREATE PROCEDURE name_in_4(IN `time` VARCHAR(50)) -- DECLARE creates a variable using BEGIN
DECLARE `time` DEFAULT 'wo'; -- DECLARE creates a variable that is only valid in the begin-end statement block SELECT NOW() ,`time`;-- 
END ;;
-- You can use DECLARE in a stored procedure -- Create (DECLARE) and assign (SET) values ​​set @variable name = value -- In summary, DECLARE is only valid in the begin-end statement block. Adding @ to set means that the session variable is valid for the connected client in the current connection. 

Use of out parameters

OUT parameters are used only to pass information back from a procedure.
MySQL stored procedure "out" parameter: pass the value from the stored procedure to the caller.
The initial value of this parameter is null, regardless of whether the caller sets a value for the stored procedure parameter.

DELIMITER ;; 
CREATE PROCEDURE name_out(IN `one` INT , IN two INT ,OUT shu INT) -- Use of out output parameter BEGIN
 
SET shu=`one`+two; -- directly add two input parameters and assign them to the output parameter set. The variable name means assignment -- set assignment is valid in the current stored procedure. For example, you can use select shu;
 -- set @The value assigned is valid in the currently connected client END ;;
 
 
CALL name_out(3,3,@shuchu);
SELECT @shuchu AS output parameter; -- When calling a stored procedure, you can define an @ parameter to receive the output parameter, that is, the return value. 

The above is the introduction to the detailed use of MySql stored procedure parameters introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

You may also be interested in:
  • MySQL stored procedure example (including transactions, output parameters, nested calls)
  • MySQL stored procedure example with input and output parameters
  • MySQL stored procedure parameter passing to implement where id in (1,2,3,...) example
  • How to create stored procedures with IN and OUT parameters in MySQL
  • In-depth explanation of how to pass table names using parameters in MySQL stored procedures
  • Detailed explanation of the three types of MySQL stored procedure parameters (in, out, inout)
  • mysql stored procedure input and output parameter examples
  • Detailed example of MySQL data storage process parameters
  • MySQL stored procedure in, out and inout parameter examples and summary

<<:  A brief discussion on React Component life cycle functions

>>:  Implementation of effective user groups and initial user groups in Linux

Recommend

Several commonly used methods for centering CSS boxes (summary)

The first one: Using the CSS position property &l...

How to use React forwardRef and what to note

Previously, react.forwardRef could not be applied...

Vue-Router installation process and principle detailed

Table of contents 1. Front-end routing implementa...

How to implement a lucky wheel game in WeChat applet

I mainly introduce how to develop a lucky wheel g...

JavaScript function syntax explained

Table of contents 1. Ordinary functions 2. Arrow ...

JavaScript anti-shake and throttling explained

Table of contents Stabilization Throttling Summar...

Html comments Symbols for marking text comments in Html

HTML comments, we often need to make some HTML co...

Summary of using the exclamation mark command (!) in Linux

Preface Recently, our company has configured mbp,...

How to install mysql6 initialization installation password under centos7

1. Stop the database server first service mysqld ...

Detailed Example of MySQL curdate() Function

MySQL CURDATE Function Introduction If used in a ...

CSS to achieve compatible text alignment in different browsers

In the front-end layout of the form, we often nee...

MYSQL unlock and lock table introduction

MySQL Lock Overview Compared with other databases...

Detailed explanation of the update command for software (library) under Linux

When installing packages on an Ubuntu server, you...

How to reset the root password in mysql8.0.12

After installing the database, if you accidentall...