62

私は次のことを試しました -

次のようにコマンドプロンプトで変数を作成しました-

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

次に、それを表示するために、次のことを試しましたが成功しませんでした-

    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か?

4

3 に答える 3

93

単にSELECT次のような変数:

SELECT @myId;

ユーザー定義変数に関する MySQL ドキュメントは次のとおりです。

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

于 2013-09-16T22:53:48.337 に答える