Say I have a select statement that goes..
select * from animals
That gives a a query result of all the columns in the table.
Now, if the 42nd column of the table animals
is is_parent
, and I want to return that in my results, just after gender
, so I can see it more easily. But I also want all the other columns.
select is_parent, * from animals
This returns ORA-00936: missing expression
.
The same statement will work fine in Sybase, and I know that you need to add a table alias to the animals
table to get it to work ( select is_parent, a.* from animals ani
), but why must Oracle need a table alias to be able to work out the select?
The Oracle SELECT clause:After the Oracle SELECT keyword, specify the names of the columns that you would like to retrieve, separated by comma (,). You can specify as many columns as you want; you can even specify the same column more than once. The columns appear in the order selected.
To select columns, choose one of the following options: Type SELECT , followed by the names of the columns in the order that you want them to appear on the report. Use commas to separate the column names.
If the submitted statement is the same as a reusable SQL statement in the shared pool, then Oracle Database reuses the existing code. This is called Soft parse. in case of hard parsing the server process will approach the optimizer, who will read the sql statement and generate the execution plan of the query.
Actually, it's easy to solve the original problem. You just have to qualify the *.
select is_parent, animals.* from animals;
should work just fine. Aliases for the table names also work.
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