I have an oracle database table with a lot of columns that I'm running some queries on.
I don't know exactly what data I'm looking for in my query, so I want to return all columns, but I don't want to hunt and peck for columns I know are meaningful.
Supposing a table (Table 1) with Column A, Column B, Column C....Column Z --
Is there a way to essentially say "Select Column C, Column J, Column F, Column Q, and then the rest of the columns From Table 1" ?
Keeping with pseudo-sql, Running:
Select Column C, Column J, Column F, Table1.* from Table1
Doesn't help, because even though I don't mind the duplicates, oracle sees them as ambiguously defined columns and thus returns an error.
There is no nice and easy way to do this, other than specifying each column.
But if you don't mind the duplicates and you don't care about the column names, you could alias those columns:
Select
ColumnC as ColumnC1,
ColumnJ as ColumnJ1,
ColumnF as ColumnF1,
t.*
from
Table1 as t
Just for demonstration, I aliased Table1 as well. You may omit the as
keyword, but I feel it makes it a little more readable.
Do note that while these extra columns are not at all difficult for Oracle to query, they do generate extra traffic. For testing, this solution is fine, but in production code, I would opt to only select the columns you need, and only select them once. It's only a little extra work. After all, how many columns do you have? :)
You can work around the problem, however, by aliasing the columns that you are specifically selecting. For example
SELECT columnC new_columnC, columnJ new_columnJ, columnF new_columnF, t.*
FROM table1 t
to ensure that there are no identically named columns.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With