![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
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
How to declare a variable correctly in a MySQLProcedure?\n
The variable declaration must be between BEGIN and END. Under BEGIN and END, the first statement must be declaration of variable. After that you can include insert, select, etc.
Let us now see an example. Here, the variable name is “output”:
mysql> DELIMITER // mysql> CREATE PROCEDURE showVariablesValue() -> BEGIN -> DECLARE output varchar(100); -> SET output="Hello MySQL"; -> SELECT output; -> END -> // Query OK, 0 rows affected (0.25 sec) mysql> DELIMITER ;
Now you can call the stored procedure using call command:
mysql> CALL showVariablesValue();
This will produce the following output
+-------------+ | output | +-------------+ | Hello MySQL | +-------------+ 1 row in set (0.03 sec) Query OK, 0 rows affected (0.04 sec)
Advertisements