Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is selecting specified columns, and all, wrong in Oracle SQL?

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?

like image 408
glasnt Avatar asked Feb 23 '10 00:02

glasnt


People also ask

How do I SELECT a specific column in Oracle?

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.

How do you specify the columns to be 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.

How the SELECT statement works in Oracle?

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.


1 Answers

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.

like image 134
Jim Hudson Avatar answered Sep 28 '22 04:09

Jim Hudson