0

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?

124697
  • 22,097
  • 68
  • 188
  • 315

4 Answers4

3

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

Steve
  • 53,375
  • 33
  • 96
  • 141
3

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

Community
  • 1
  • 1
jmj
  • 237,923
  • 42
  • 401
  • 438
  • I don't want to return the columns at all. I don't care what columns are returned because I'm just testing a data grid and its too small for a lot of columns – 124697 Dec 31 '10 at 16:50
  • Are you just trying to stress test a data grid? Why not return all the columns then? – Steve Dec 31 '10 at 16:51
  • 5
    If you don't care about what columns are return then just type in the first ten column names in the select statement.. how hard can that be??? seriously?? – clyc Dec 31 '10 at 16:57
  • @clyc that's not the point. I can write all 50 but I'm wondering if there's a way of doing it. its a straight froward question. if you don't have an answer don't don't answer – 124697 Dec 31 '10 at 18:11
  • 1
    As everyone has already mentioned, there isn't a simple way of doing it without making your life any more complicated as org.life.java pointed out. You would have build out a dynamic sql query in order to achieve this. With what you are using this for, there is no point to do this and the best and most efficient way would be to just type in the names of 10 columns. Returning all 9000 columns every time = waste of network resources. BTW, I didn't submit an "answer" since everyone else already stated the fact. I only posted a comment... – clyc Dec 31 '10 at 18:37
3

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.

chx
  • 11,270
  • 7
  • 55
  • 129
1

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.

Community
  • 1
  • 1
Ronnis
  • 12,593
  • 2
  • 32
  • 52