Home > Database > Mysql Tutorial > body text

MySQL stored procedure: output parameters?

WBOY
Release: 2023-09-15 19:45:15
forward
574 people have browsed it

MySQL stored procedure: output parameters?

This is a stored procedure that takes one parameter as input (IN) and the second parameter as output (OUT)

mysql> delimiter //
mysql> create procedure Sp_SQRT(IN Number1 INT, OUT Number2 FLOAT)
   -> Begin
   -> set Number2=sqrt(Number1);
   -> end;
   -> //
Query OK, 0 rows affected (0.24 sec)
mysql> delimiter ;
Copy after login

Call the stored procedure and put the value Sent to user variable. The syntax is as follows

CALL yourStoredProcedureName(anyIntegerValue,@anyVariableName);
Copy after login

Check the value stored in the variable @anyVariableName. The syntax is as follows

SELECT @anyVariableName;
Copy after login

A stored procedure named "Sp_SQRT" is created. The query to call the stored procedure is as follows

mysql> call Sp_SQRT(36,@MySquareRootNumber);
Query OK, 0 rows affected (0.02 sec)
Copy after login

Use the select statement to check the value of the variable @MySquareRootNumber

mysql> select @MySquareRootNumber;
Copy after login

The following is the output

+---------------------+
| @MySquareRootNumber |
+---------------------+
|                   6 |
+---------------------+
1 row in set (0.00 sec)
Copy after login

The above is the detailed content of MySQL stored procedure: output parameters?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!