Home > Database > Mysql Tutorial > How to display the value of a variable in MySQL command line?

How to display the value of a variable in MySQL command line?

PHPz
Release: 2023-09-17 16:57:02
forward
1597 people have browsed it

How to display the value of a variable in MySQL command line?

To display the value of a variable, you can use the select statement. The syntax is as follows -

SELECT @yourVariableName;
Copy after login

Let us first create a variable. This can be done using the SET command. Following is the syntax to create a variable -

SET @yourVariableName = yourValue;
Copy after login

Let us check the above syntax to create a variable and display the value of the created variable.

The following is the query to create the variable -

mysql> set @FirstName = 'Bob';
Query OK, 0 rows affected (0.04 sec)
Copy after login

Now you can display the value of the variable using select statement. The query is as follows-

mysql> select @FirstName;
Copy after login

The following is the output-

+------------+
| @FirstName |
+------------+
| Bob        |
+------------+
1 row in set (0.03 sec)
Copy after login

Let us see another example and declare a real type with a value-

mysql> set @Amount = 150.56;
Query OK, 0 rows affected (0.00 sec)
Copy after login

Display the value using select statement-

mysql> select @Amount;
Copy after login

The following is the type output showing the variable value-

+---------+
| @Amount |
+---------+
| 150.56  |
+---------+
1 row in set (0.00 sec)
Copy after login

The above is the detailed content of How to display the value of a variable in MySQL command line?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template