开发者

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

开发者 https://www.devze.com 2023-02-02 03:04 出处:网络
I\'ve got an oracle database and a table that has a lot of columns and ro开发者_Go百科ws.. I want to return onl the first 10 columns to my JTables but I don\'t want to name each column in my query.

I've got an oracle database and a table that has a lot of columns and ro开发者_Go百科ws.. 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?


Nope, but even if it was, you would want to write them out, as the order may change.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消