question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ORA-00918: column ambiguously defined

See original GitHub issue

Using Oracle 12C 12.1.0 with latest EF Core 3.1 provider

I am mapping to an existing user/schema/database (: and are not in charge of it.

I have a contact person that have a contact type. I only have navigation to the ContactType

When I run this code

var contact = context.Contacts.Include(x=>x.Type).FirstOrDefault();

That produces this sql:

 fail: Microsoft.EntityFrameworkCore.Database.Command[20102]
      Failed executing DbCommand (67ms) [Parameters=[], CommandType='Text', CommandTimeout='0']
      SELECT "c"."ID", "c"."TYPE", "c"."CUSTOMER", "c"."EMAIL", "c"."NAME", "c"."PHONE", "c0"."ID", "c0"."NAME"
      FROM "SAMSON"."CUSTOMER_CONTACT" "c"
      INNER JOIN "SAMSON"."CUSTOMER_CONTACT_TYPE" "c0" ON "c"."TYPE" = "c0"."ID"
      FETCH FIRST 1 ROWS ONLY

I have no problems running the sql: Is it an error, or are my relation mapping wrong?

SELECT "c"."ID", "c"."TYPE", "c"."CUSTOMER", "c"."EMAIL", "c"."NAME", "c"."PHONE", "c0"."ID", "c0"."NAME"
FROM "SAMSON"."CUSTOMER_CONTACT" "c"
INNER JOIN "SAMSON"."CUSTOMER_CONTACT_TYPE" "c0" ON "c"."TYPE" = "c0"."ID";

contact_domain contact_type_domain samson_contact contact_mapping contact_type_mapping

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:15 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
alexkehcommented, Sep 24, 2020

@Martin-Andersen Yes, the bug does not occur in DB 12.2 and higher as it does in DB 12.1. I was assured by the SQL dev team the recommended solution is to upgrade to 12.2 or higher if aliases can’t be used.

1reaction
alexkehcommented, Sep 23, 2020

@Martin-Andersen There aren’t really any good solutions.

EF Core doesn’t have a way for providers to retrieve the DB server version. Thus, if ODP.NET EF Core generates aliases, it would have to make this change for all DB versions, not just 12.1. Now, I’m not sure if aliases can be used in this way in LINQ. I’ll find out.

The SQL generated is actually correct. DB 12.1 has a known, documented issue. If the select list contains columns with identical names and you specify the row_limiting_clause, then an ORA-00918 error occurs. This error occurs whether the identically named columns are in the same table or in different tables. You can work around this issue by specifying unique column aliases for the identically named columns.

This issue was fixed in 12.2, but was not backported to 12.1. Essentially, the “patch” is to move to DB 12.2 or higher.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ORA-00918: column ambiguously defined tips
ORA-00918 column ambiguously defined. Cause: A column name used in a join exists in more than one table and is thus referenced ambiguously....
Read more >
ORA-00918: column ambiguously defined
The source of an ORA-00918 error comes from a mistake when attempting to join two or more tables that share the same name...
Read more >
ORA-00918: column ambiguously defined in SELECT
The solution is quite simple: you will have to expand the projection to explicitly select named columns. Then you can either leave out...
Read more >
Oracle / PLSQL: ORA-00918 Error Message
Cause. You tried to execute a SQL statement that joined two or more tables, where a column with the same name exists in...
Read more >
Ora 00918 Column Ambiguously Defined: Solved Efficiently
Ora 00918 column ambiguously defined means that your Oracle database is unable to determine which table a column belongs to because you specified...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found