- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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)
Advertisements