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!