如何在MySQL的命令行显示变量的值? [英] How to display the value of a variable at the commandline in MySQL?

查看:1663
本文介绍了如何在MySQL的命令行显示变量的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试过以下 -

我在命令提示符处创建了一个变量,如下所示 -

I created a variable at the command prompt as follows -

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

尝试以下操作但未成功 -

Then, to display it, I tried the following without success -

    mysql> show myId;
    ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that 
corresponds to your MySQL server version for the right syntax to use near 'myId' at line 1
    mysql> show @myId;
    ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near '@myId' at line 1
    mysql> PRINT @myId;
    ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that 
corresponds to your MySQL server version for the right syntax to use near 'PRINT @myId' at line 1
    mysql> PRINT myId;
    ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that 
corresponds to your MySQL server version for the right syntax to use near 'PRINT myId' at line 1

那么如何显示 @myId 的值?

推荐答案

只需 SELECT b
$ b

Simply SELECT the variable like this:

SELECT @myId;

这里是关于用户定义变量的MySQL文档:

Here is the MySQL documentation on user-defined variables:

http://dev.mysql.com/ doc / refman / 5.5 / en / user-variables.html

这篇关于如何在MySQL的命令行显示变量的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆