Search code examples
sqloracle9i

SQL select from table with alias (Oracle9i)


According to Oracle documentation for statement SELECT it should be possible to alias table names with aliases without or with keyword AS. However, aliasing tables with keyword AS leads to error:

ORA-00933: SQL command not properly ended

For example, the following statement fails with the above error:

SELECT COUNT(*) FROM MY_TABLE AS A;

Once keyword AS is removed it executes as expected.

Could anyone please comment on this. Is there a way to make the application of AS for table aliasing work?

P.S. I'm using a code generation utility that translate some Java code into SQL statements at runtime. This utility enforces the use of aliases with AS.


Solution

  • Oracle does not accept AS for table aliases and I see no way to make it work.

    Can't you do anything in Java? AS for column aliases is optional in Oracle, so you could look for all " AS " in the generated string and remove them (thus removing AS for column aliases as well as for table aliases). Is this an option?