How can user variables be used in MySQL stored procedure?

MySQLMySQLi Database

In MySQL stored procedure, user variables are referenced with an ampersand i.e. @, prefixed to the user variable names. For example, @A, @B, etc. are user variables. To demonstrate it, we are creating the following procedure −

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)
raja
Published on 21-Feb-2018 12:39:47
Advertisements