Why doesn't Oracle raise “ORA-00918: column ambiguously defined” for this query?

倾然丶 夕夏残阳落幕 提交于 2019-11-28 11:56:27

Can't say when it was fixed, but here's my results:

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options

SQL> SELECT *
  2  FROM USER_TABLES TAB
  3  JOIN USER_TRIGGERS TRG ON TRG.TABLE_NAME = TAB.TABLE_NAME
  4  WHERE STATUS = 'DISABLED';
WHERE STATUS = 'DISABLED'
      *
ERROR at line 4:
ORA-00918: column ambiguously defined

SQL> ed
Wrote file afiedt.buf

  1  SELECT *
  2  FROM USER_TABLES TAB
  3  JOIN USER_TRIGGERS TRG ON TRG.TABLE_NAME = TAB.TABLE_NAME
  4  JOIN USER_CONSTRAINTS CON ON CON.TABLE_NAME = TAB.TABLE_NAME
  5* WHERE STATUS = 'DISABLED'
SQL> /
WHERE STATUS = 'DISABLED'
      *
ERROR at line 5:
ORA-00918: column ambiguously defined

Searched Oracle Support and found this:

Bug 5368296 - ANSI join SQL may not report ORA-918 for ambiguous column [ID 5368296.8]

Versions confirmed as being affected:

  • 10.2.0.3
  • 10.2.0.4

This issue is fixed in

  • 10.2.0.4 Patch 2 on Windows Platforms
  • 10.2.0.5 (Server Patch Set)
  • 11.1.0.6 (Base Release)

Not posting more than that since you need an Oracle Support account to view the details, but thought the Oracle Bug number/versions affected would be okay to share to point you in the right direction on Oracle Support.

You are using ANSI SQL. I'm guessing that it associates the STATUS in the where clause with the driving table.

When you use "oracle" syntax you'll see the expected behaviour.

SELECT *
FROM USER_TABLES TAB, USER_TRIGGERS TRG, USER_CONSTRAINTS CON
WHERE TRG.TABLE_NAME = TAB.TABLE_NAME
AND CON.TABLE_NAME = TAB.TABLE_NAME
AND STATUS = 'DISABLED'

More confirmed bug about this here: http://oracledoug.com/serendipity/index.php?/archives/1555-Bug-Hunting.html

Latest update is that it's fixed in 11.2.0.2

Well, if I try this on 11.2.0.2.0, I get the same issue. Regardless of the functionality, if you add in some left and right joins, this bug does not seem to be fixed at all!

SELECT *
FROM USER_TABLES TAB
LEFT JOIN USER_TRIGGERS TRG ON TRG.TABLE_NAME = TAB.TABLE_NAME
RIGHT JOIN USER_CONSTRAINTS CON ON CON.TABLE_NAME = TAB.TABLE_NAME
WHERE STATUS = 'DISABLED'
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!