Is the 'as' keyword required in Oracle to define an alias?
According to the select_list Oracle select documentation the AS is optional.
As a personal note I think it is easier to read with the AS
(Tested on Oracle 11g
)
About AS
:
- When used on result column,
AS
is optional. - When used on table name,
AS
shouldn't be added, otherwise it's an error.
About double quote
:
- It's optional & valid for both result column & table name.
e.g
-- 'AS' is optional for result column
select (1+1) as result from dual;
select (1+1) result from dual;
-- 'AS' shouldn't be used for table name
select 'hi' from dual d;
-- Adding double quotes for alias name is optional, but valid for both result column & table name,
select (1+1) as "result" from dual;
select (1+1) "result" from dual;
select 'hi' from dual "d";
AS without double quotations is good.
SELECT employee_id,department_id AS department
FROM employees
order by department
--ok--
SELECT employee_id,department_id AS "department"
FROM employees
order by department
--error on oracle--
so better to use AS without double quotation if you use ORDER BY clause