Home > Database > Mysql Tutorial > body text

How to use user variables in MySQL stored procedures?

PHPz
Release: 2023-08-28 12:29:02
forward
1170 people have browsed it

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)
Copy after login

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!

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!