- 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 display the value of a variable on command line in MySQL?
To display the value of a variable, you can use select statement. The syntax is follows −
SELECT @yourVariableName;
Let us first create a variable. This can be done using SET command. The following is the syntax to create a variable −
SET @yourVariableName = yourValue;
Let us check the above syntax to create a variable and display the value of created variable.
The following is the query to create a variable −
mysql> set @FirstName = 'Bob'; Query OK, 0 rows affected (0.04 sec)
Now you can display the value of a variable using select statement. The query is as follows −
mysql> select @FirstName;
The following is the output −
+------------+ | @FirstName | +------------+ | Bob | +------------+ 1 row in set (0.03 sec)
Let us see another example and declare a real type with value −
mysql> set @Amount = 150.56; Query OK, 0 rows affected (0.00 sec)
Display value using select statement −
mysql> select @Amount;
The following is type output displaying the value of the variable −
+---------+ | @Amount | +---------+ | 150.56 | +---------+ 1 row in set (0.00 sec)
Advertisements