
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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?
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)
- Related Questions & Answers
- How to declare a variable in C++?
- How to declare a variable in MySQL?
- How to declare a variable in Python?
- MySQL how to declare a datetime variable?
- How to declare a local variable in Java?
- How to declare a global variable in C++
- How to declare a global variable in PHP?
- How to declare a global variable in Python?
- 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 within lambda expression in Java?
- How to declare a variable in Python without assigning a value to it?
- How do I declare a global variable in Python class?
- How do we declare variable in Python?
- Can we declare a static variable within a method in java?
Advertisements