Question

I know there are lots of questions like these, but my question is not how to get rid of this error but to know how this worked earlier in 9-th version of Oracle.

I've got an old sources written in Ruby and Oracle DB which recently was upgraded to version=11.

I cannot edit data in Oracle DB, only read. so there are two tables lets say: table A(id, name, type, customer) and table B(id,a_id,type,person)

so. there is a query in the source code:

select a.id,b.id from a join b on a.id = b.a_id where type = 'A'

so in Oracle 9 this worked perfectly but now i've got "column ambiguously defined" error.

What i'd like to know is:

where type = 'A'

is the same as

where a.type = 'A' AND b.type = 'A'

or

where a.type = 'A' OR b.type = 'A'

?

Was it helpful?

Solution

I think this was a bug with the ANSI style join. Use DBMS_XPLAN to find which table was being filtered in the old database.

Or better still, work out from the business logic what they query SHOULD have been.

OTHER TIPS

No, and that's the problem: It could mean

where a.type = 'A'

or it could mean

where b.type = 'A'

with potentially different results; hence the error saying it is ambiguously defined.

I think you should test in Oracle 9 (where you say it works) and compare the output of the ambiguous query:

--- Base
select a.id,b.id from a join b on a.id = b.a_id where type = 'A'

with both the non-ambiguous ones:

--- QueryA
select a.id,b.id from a join b on a.id = b.a_id where a.type = 'A'

and:

--- QueryB
select a.id,b.id from a join b on a.id = b.a_id where b.type = 'A'

Something like this would do:

select a.id,b.id from a join b on a.id = b.a_id where type = 'A'
MINUS
select a.id,b.id from a join b on a.id = b.a_id where a.type = 'A'

(in short):

(Base)
MINUS
(QueryA)

and then:

(QueryA)
MINUS
(Base)

If both of the above MINUS queries return 0 rows, then BASE query is interpreted as QueryA.

Check similarly and compare Base with QueryB.


Another plausible reason for this error is that during (or about the same period with ) the migration, a type column was added in the 2nd table. Do you have old versions of the database tables' definitions to check that?

All - keep in mind there was a major change to the optimization engine for 11g. If you set your query optimizer level to 10.2.x on your 11g instance I bet the query would start working again.

That being said you should provide the alias for it so it's not ambiguous to the database server or the DBA / Developer coming behind you. :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top