Sorry if it\'s trivial, but selecting column with *
sign isn\'t working always, and I don\'t find reference to this behavior.
I can select table A
Why are the errors so misleading?
The errors are correct. They just don't guess what you are trying to do. After
select *
the next keyword should be from
, so anything else gives
FROM keyword not found where expected
After ,
there should be a valid expression such as a column name, not *
which is unexpected, so you get
ORA-00936: missing expression
Perhaps it would be nice if Oracle wrote a special error message about the incorrect use of *
, but so far they have not. You could propose it on the Oracle Database Ideas forum.
The syntax diagram for select shows:
The outermost path of that shows the plain, unprefixed *
all-column wildcard on its own, and there is no loop back around for additional column expressions - all paths with a comma (to separate terms) are distinct from that plain *
path.
On the inner path that does allow a comma, and thus multiple expressions, you can only use .*
prefixed by a table/view/alias, and can then follow (or precede) that with other expressions.
(I really thought that was stated more clearly somewhere, but I can't find it anywhere in recent documentation...)
Why i must use the alias for * sign ?
select col,aa.* from A aa;
That isn't quite accurate; you don't have to use an alias, you can use the table name directly if it isn't aliased, so this is also valid:
select col,A.* from A;
There is a school of thought that you shouldn't use a wildcard anyway, at least for anything except an ad hoc query - it's better to list all of the required column name explicitly, prefixed with the appropriate table name/alias particularly if there is a join, for clarity and to avoid unexpected issues with tables being modified. That's rather outside the scope of this question though *8-)
The restriction is not so clearly stated in documentation, but you can find it by following this diagram.
Here you see that if you use the *
, you can't use anything else in select list