Average Population

  • + 1 comment

    It's not broken; your syntax is OK for MS SQL but not for Oracle; for Oracle, AS is only valid syntax when aliasing columns and not when aliasing table names. If you were to try

    SELECT 
        c.ID AS i
    FROM 
        City c;
    

    it will execute fine, because that is correct syntax for Oracle. I don't know the specific reason for it (though there are some legitimate arguments out there against using AS), but it's mentioned in many places such as some Oracle forums, techonthenet, and Oracle's SELECT documentation's mentions of Column Alias:

    c_alias 
    Specify an alias for the column expression. Oracle Database will use this alias in the column heading of the result set. The AS keyword is optional. The alias effectively renames the select list item for the duration of the query. The alias can be used in the order_by_clause but not other clauses in the query.
    

    and Table Alias

    t_alias
    Specify a correlation name, which is alias for the table, view, materialized view, or subquery for evaluating the query. This alias is required if the select list references any object type attributes or object type methods. Correlation names are most often used in a correlated query. Other references to the table, view, or materialized view throughout the query must refer to this alias.
    

    There is no mention of AS syntax being allowable for t_alias in Oracle's Database SQL Language Reference, and indeed every example they have (in the lang ref for correlated subqueries, subclauses, etc.) uses the syntax:

    FROM table t_alias