简体   繁体   中英

IBM DB2 Select named column, then select *

I can't seem to figure out how to do the following in an IBM DB2 select statement:

SELECT column1, *
FROM [some table]

I get the following error:

SELECT ACCT_NUM, * FROM GEG1.RENL_RATING_STRUC
SQL0104N  An unexpected token "*" was found following "".  Expected tokens may include:  "+ - ROW NEXTVAL PREVVAL NEXT PREVIOUS ( <INTEGER> <DECIMAL>".  SQLSTATE=42601

I searched for a syntax document, but I couldn't find one. Can anyone help with this?

If you give the table an alias, you can prefix the asterisk with the alias to do what you want:

SELECT A.id, A.*
FROM your_table A

You have to interpret the select-clause definition from this page :

           .-ALL------.   
>>-SELECT--+----------+----------------------------------------->
           '-DISTINCT-'   

>--+-*-----------------------------------------------+---------><
   | .-,-------------------------------------------. |   
   | V                                             | |   
   '---+-expression--+-------------------------+-+-+-'   
       |             | .-AS-.                  | |       
       |             '-+----+--new-column-name-' |       
       '-exposed-name.*--------------------------'       

So, this basically reads "you can SELECT * OR you can select multiple expressions (a column) or exposed-name.* , separated by a comma".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM