Home  >  Article  >  Database  >  How to use user variables in MySQL stored procedures?

How to use user variables in MySQL stored procedures?

PHPz
PHPzforward
2023-08-28 12:29:021171browse

How to use user variables in MySQL stored procedures?

In MySQL stored procedures, user variables are referenced with an ampersand (i.e. @) and are prefixed with the user variable name. For example, @A, @B, etc. are all user variables. To demonstrate it we are creating the following process -

mysql> DELIMITER // ;
mysql> CREATE PROCEDURE Proc_Uservariables()
   -> BEGIN
   -> SET @A = 100;
   -> SET @B = 500;
   -> SELECT @A,@B,@A+@B;
   -> END //
Query OK, 0 rows affected (0.00 sec)

mysql> Delimiter ; //
mysql> CALL Proc_Uservariables();
+------+------+-------+
| @A   | @B   | @A+@B |
+------+------+-------+
|  100 |  500 |   600 |
+------+------+-------+
1 row in set (0.00 sec)

Query OK, 0 rows affected (0.01 sec)

The above is the detailed content of How to use user variables in MySQL stored procedures?. 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