简体   繁体   中英

SQL How to return only a number of columns, say the first 10 without specifying them in the SQL query

I've got an oracle database and a table that has a lot of columns and rows.. I want to return onl the first 10 columns to my JTables but I don't want to name each column in my query.

Is it possible?

edit: isnt there a column index? or something like rownum but for columns?

不会,但是即使这样,您也可能想将它们写出来,因为顺序可能会更改。

I don't want to name each column in my query.

You can programatically fetch column name and can generate query on fly and then can obtain your goal

SQL deals with sets and properties of sets by definition have no order. http://en.wikipedia.org/wiki/File:Relational_model_concepts.png see Attribute (column) unordered. Literally what you are asking for has no meaning.

There are ways of doing what you want, but you shouldn't because that ties your implementation to a physical table layout. This is a bad thing.

See How do I exclude columns... and Select vs select column..

If, after reading those questions you still want to do this, you can have a look at USER_TAB_COLUMNS . The column COLUMN_ID will contain the sequence number of the column as created. You could then select COLUMN_NAME where COLUMN_ID <= 10 , and find a way of constructing a query with those columns.

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