In IBM Engineering Workflow Management (EWM), a work item query fails to execute due to ORA-00918 "column ambiguously defined" error Show
SymptomSteps to reproduce:
The following error is returned:
Notes:
CauseUnsupported Oracle database version is used with EWM 7.0.2. The problem is reproducible in EWM 7.0.2 running with Oracle 12c Release 1 and 12.2.0.1.0 JDBC driver. EnvironmentEWM 7.0.2 Oracle 12c Release 1 with 12.2.0.1.0 driver Diagnosing The Problem
The failed database query contains an 'order by' clause that has two or more columns with the same name. The following example shows t1.ID and t4.ID.
Resolving The Problem
Related InformationELM 7.0.2 System Requirement documentation Document LocationWorldwide [{"Type":"MASTER","Line of Business":{"code":"LOB59","label":"Sustainability Software"},"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Product":{"code":"SSUC3U","label":"IBM Engineering Workflow Management"},"ARM Category":[{"code":"a8m50000000Cjd6AAC","label":"Workflow Management->Work Items"}],"ARM Case Number":"TS007861042","Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"7.0.2"}] ORA-00918: column ambiguously defined error occurs when a column name in a join exists in more than one table and is thus referenced ambiguously. The ORA 00918 column ambiguously defined error occurs when attempting to join two or more tables with the same name across columns. This column name is referred as an ambiguous reference. If a column with the same name exists in two or more tables, the column name should be prefixed with the table name in joins. Otherwise, the column is identified ambiguously in the join, and the sql query is unable to determine the column name from the tables. In this scenario, the error message ORA-00918: column ambiguously defined will be shown. The joins in the sql query combine all of the columns from two or more tables. If a column name is used in two or more tables, the column name is ambiguously recognized in the SQL join. Oracle will give an error ORA-00918: column ambiguously defined, if the column name is used to refer. The reference to the column name should be distinguished in some way. There are several methods for uniquely identifying the column names in the join. When the ORA-00918 error occurIf two or more tables with the same column name are created and joined in a sql query, the column name may be recognized ambiguously. Because the column name is available in all of the join tables, Oracle could not match with any one table to get the data. The error ORA-00918: column ambiguously defined will be thrown in this scenario. Problem
Error
Root CauseIf more than one table includes the same column name and refers to those columns in a join, the column name will be ambiguous. Oracle will search in the joined tables if you refer to the column name. If the same column name appears in two or more tables, the column name is identified ambiguously. With those tables, the join could not be performed. There is no way to distinguish the columns. Solution 1If the same column name appears in multiple tables and is referenced in a join, the column name becomes ambiguous. In sql joins, the column name is identified ambiguously. It is necessary to differentiate the columns in the joins. One method is to prefix the table name when referring it in joins. The table name is used to uniquely identify the column name. Problem
Solution
Solution 2The column name becomes ambiguous if it occurs in many tables and is referenced in a join. The column name is ambiguously recognized in sql joins. In order to separate the columns in the joins, they must be differentiated. If you use the same table in a sql join again, referencing the column by table name will fail. The table alias should be used to refer to the column name in this situation. Problem
Solution
Solution 3When a column name appears in many tables and is referenced in a join, it becomes confusing. In sql joins, the column name is recognized ambiguously. The columns in the joins must be distinct in order to be separated. You may use a select query to change the column names before using them in joins. The select query will provide a list of unique column names to which you may refer. In the example below a select query is used in the joins. How do you resolve the Oracle error Ora 00918 column ambiguously defined?Check to see if this table has column STATUS or ID_TYPE (or perhaps both). Then find what other table or tables has/have columns with the same name(s). To fix the problem, decide from which table you should select those columns. You shouldn't have any unqualified column names in a query like this.
What does it mean by column ambiguously defined?ORA-00918 column ambiguously defined. Cause: A column name used in a join exists in more than one table and is thus referenced ambiguously. In a join, any column name that occurs in more than one of the tables must be prefixed by its table name when referenced. The column should be referenced as TABLE.
How to fix invalid identifier in Oracle?Ora-00904 Error Message “Invalid Identifier”
This error is most common when querying a SELECT statement. To resolve this error, first check to make sure the column name being referenced exists. If it does not exist, you must create one before attempting to execute an SQL statement with the column.
How does left join work in Oracle?The LEFT JOIN keyword returns all records from the left table (table1), and the matching records from the right table (table2). The result is 0 records from the right side, if there is no match.
|