Sometimes we assume things to work and not test it, but it surprise you and give you a reason to learn.
We have a product that works on top of both Oracle and SQL Server, hence we are bound to compliant SQL syntax as ANSI or validated on both.
For one of our changes, we had written SQL as below to run on both SQL Server and Oracle.
SELECT COL1 AS COLUMN1 FROM TABLE1 AS TABLE_ALIAS
As it being a simple change,we (Primarily I) only tested on SQL Server and was confident enough that it will work in Oracle.
But is unfold surprise with below Exception in Oracle and works fine in SQL Server.
ORA-00933: SQL command not properly ended
00933. 00000 - "SQL command not properly ended"
lets try to understand with Example in Oracle,
select 'Hi Error' AS Hello from DUAL AS d;
We are using AS keyword to define alias for both Column and Table.
In Oracle, “AS” keyword for Alias only works for Column and not for Table. Didn’t find anything on oracle documentation.
Finally had changed to similar SQL as below.
select 'Hi Error' AS Hello from DUAL d;
Learning, Test and don’t assume.!