Home  >  Article  >  Database  >  MySQL stored procedure: output parameters?

MySQL stored procedure: output parameters?

WBOY
WBOYforward
2023-09-15 19:45:15576browse

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 ;

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

CALL yourStoredProcedureName(anyIntegerValue,@anyVariableName);

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

SELECT @anyVariableName;

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)

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

mysql> select @MySquareRootNumber;

The following is the output

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

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete