
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
How can user variables be used in MySQL stored procedure?
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)
- Related Articles
- How can local variables be used in MySQL stored procedure?
- How Can MySQL CASE statement be used in stored procedure?
- How MySQL IF statement can be used in a stored procedure?
- How MySQL WHILE loop statement can be used in stored procedure?
- How MySQL REPEAT loop statement can be used in stored procedure?
- How Can MySQL LOOP statement be used in a stored procedure?
- How MySQL IF ELSE statement can be used in a stored procedure?
- How can MySQL IF ELSEIF ELSE statement be used in a stored procedure?
- How can a MySQL stored procedure call another MySQL stored procedure inside it?
- Create variables in MySQL stored procedure with DECLARE keyword
- How can we invoke MySQL stored procedure?
- How can we alter a MySQL stored procedure?
- How can we drop a MySQL stored procedure?
- How can I create MySQL stored procedure with IN parameter?
- How can we write MySQL handler in a stored procedure?

Advertisements