
- 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
Using DECLARE to create variable in MySQL?
You can use DECLARE in a stored procedure. The syntax is as follows −
declare yourVariableName yourDataType;
To understand the above syntax, let us create a stored procedure:
mysql> delimiter // mysql> create procedure square_demo(in Value int) begin declare magicValue int; set magicValue=Value; select concat('Your Square Value=',magicValue*magicValue) as Output; end ; // Query OK, 0 rows affected (0.00 sec) mysql> delimiter ;
Now you can call a stored procedure using call command −
mysql> call square_demo(15);
This will produce the following output −
+-----------------------+ | Output | +-----------------------+ | Your Square Value=225 | +-----------------------+ 1 row in set (0.00 sec) Query OK, 0 rows affected (0.00 sec)
- Related Articles
- How to declare a variable in MySQL?
- MySQL how to declare a datetime variable?
- How to declare a variable inside a procedure in MySQL?
- How to declare a variable in MySQL for a normal query?
- How to declare a variable in C++?
- How to declare a variable in Python?
- How to declare a global variable in C++
- How to declare a local variable in Java?
- How to declare a global variable in PHP?
- How to declare a global variable in Python?
- Create variables in MySQL stored procedure with DECLARE keyword
- Declare variable as constant in C
- How do we declare variable in Python?
- MySQL CREATE USER with a variable?
- How to declare a variable correctly in a MySQLProcedure?\n

Advertisements