
- 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 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)
- Related Articles
- How to declare a variable in MySQL?
- 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?
- 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 within lambda expression in Java?
- How do I declare a global variable in Python class?
- How do we declare variable in Python?
- Using DECLARE to create variable in MySQL?
- Can we declare a static variable within a method in java?

Advertisements