Home  >  Article  >  Database  >  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
PHPzforward
2023-09-17 16:57:021532browse

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;

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;

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)

Now you can display the value of the 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 a value-

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

Display the value using select statement-

mysql> select @Amount;

The following is the type output showing the variable value-

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

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete
Previous article:Sort by in MS SQL ServerNext article:Sort by in MS SQL Server