我想查看 DB2 数据库查询中的所有列,但我想将某个列放在前面。
例如,根据我的 sql 知识,我会写类似的内容
SELECT Field2, * FROM Table
Run Code Online (Sandbox Code Playgroud)
但是上面的查询返回如下错误
SQL State: 42601
Vendor Code: -104
Message: [SQL0104] Token * was not valid. Valid tokens: ( + - ? : DAY INF NAN RID ROW RRN CASE CAST CHAR DATE DAYS HASH. Cause . . . . . : A syntax error was detected at token *.
Token * is not a valid token. A partial list of valid tokens is ( + - ? : DAY INF NAN RID ROW RRN CASE CAST CHAR DATE DAYS HASH.
This list assumes that the statement is correct up to the token.
The error may be earlier in the statement, but the syntax of the statement appears to be valid up to this point. Recovery . . . :
Do one or more of the following and try the request again: -- Verify the SQL statement in the area of the token *.
Correct the statement. The error could be a missing comma or quotation mark, it could be a misspelled word, or it could be related to the order of clauses.
-- If the error token is <END-OF-STATEMENT>, correct the SQL statement because it does not end with a valid clause.
Processing ended because the highlighted statement did not complete successfully
Run Code Online (Sandbox Code Playgroud)
您可以使用关联名称来执行此操作,如下所示:
SELECT Field1, tbl.* FROM YourTable tbl
Run Code Online (Sandbox Code Playgroud)
显然,tbl.*返回所有列,因此Field1会在结果中出现两次。