Thanks for the question, Raghavendra .
Asked: April 20, 2016 - 11:05 am UTC
Last updated: April 20, 2016 - 1:19 pm UTC
Version: 11.2
Viewed 1000+ times
You Asked
Hi Chris/Tom,
CREATE TABLE alias_test AS
SELECT level x, 'test'||to_char(level) y from dual connect by level <=10
/
select x, y from alias_test
/
select x y from alias_test
Y
--
1
2
3
...
It is a user mistake of not separating the columns of a table by comma operator(,) , instead oracle treats it as an alias.
So the values for x are shown as Y (which is another column of the same table) .
Here the table contained only two columns and we fix the issue.
If suppose table contains say 60 columns, and in the select query we had missed a comma(,) by mistake for one the columns,
then the value of a given column will be treated as the value of another column, some-times this causes a blunder, since
logic would have written assuming the column values.
I agree it is completely user's mistake, but I think oracle knows that it is the same column of the referenced table,
why oracle cannot throw a WARNING before executing the sql statement, that the another column of the same table has been
referenced as an alias in the sql statement.
Basically, I am looking for WARNINGs FOR SQL STATEMENT EXECUTION SIMILAR TO PL/SQL/PACKAGE/PROCEDURE/FUNCTION BLOCK EXECUTION.
Currently as of 12c, is there any way to identify such mistakes/get COMPILER WARNINGS for SQL statements?
Thanks,
Raghavendra B
and Chris said...
You're right, missing a comma out means that Oracle treats the next column as an alias.
I'm not aware of a way to enable any kind of SQL warnings that would tell you about this.
Is this answer out of date? If it is, please let us know via a Comment