If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Oracle > "Column ambiguously defined" - Difference in Oracle 10 and 11

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-05-10, 03:25
chris_k chris_k is offline
Registered User
 
Join Date: Mar 2010
Location: Győr, Hungary
Posts: 2
Question "Column ambiguously defined" - Difference in Oracle 10 and 11

Hi all,

I am having a challenge when moving our application from Oracle 10g to 11g. I am (well, trying) to use Oracle 11.1.0.6.0 32-bit on a Windows 7.

My problem drills down to the following query:
Code:
SELECT firstname, patient_status_cd, patient_address.city
  FROM patient
 INNER JOIN patient_address
    ON patient.patient_id = patient_address.patient_id
 INNER JOIN cd_patient_status
    ON patient.patient_status_cd = cd_patient_status.patient_status_cd;
This query executes well on oracle 10, but on 11 an ORA-00918: column ambiguously defined is displayed instead for the patient_status_cd column.

As I wrote, it runs well on 10g. But - strangely - if I change the query by changing the order of the JOIN parts, then it breaks on 10g as well. So this:
Code:
SELECT firstname, patient_status_cd, patient_address.city
  FROM patient
 INNER JOIN cd_patient_status
    ON patient.patient_status_cd = cd_patient_status.patient_status_cd;
 INNER JOIN patient_address
    ON patient.patient_id = patient_address.patient_id
breaks on 10g as well.

What I see is that Oracle has right - patient_status_cd is defined both in PATIENT and CD_PATIENT_STATUS tables. BUT, why does it run on 10g then???

Thanks for your thoughts!

Chris
Reply With Quote
  #2 (permalink)  
Old 03-05-10, 05:34
Littlefoot Littlefoot is offline
Lost Boy
 
Join Date: Jan 2004
Location: Croatia, Europe
Posts: 3,629
I don't know why, but I know that I *always* use table aliases and specify column names using those aliases. Nothing is ambiguous in that case.
Reply With Quote
  #3 (permalink)  
Old 03-05-10, 05:45
chris_k chris_k is offline
Registered User
 
Join Date: Mar 2010
Location: Győr, Hungary
Posts: 2
Yes, I have learned that now. However, my problem is that our application has hundreds of existing queries that are suspect to this issue - it would be a huge pain to re-test all of them...
Reply With Quote
  #4 (permalink)  
Old 03-05-10, 05:54
Littlefoot Littlefoot is offline
Lost Boy
 
Join Date: Jan 2004
Location: Croatia, Europe
Posts: 3,629
Well, that's the price of not following the best practices.

However, you don't have to test them all - only those that won't work any more
Reply With Quote
  #5 (permalink)  
Old 03-05-10, 07:05
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,538
Quote:
Originally Posted by Littlefoot View Post
Well, that's the price of not following the best practices.
absolutely correct

the original developers should be taken out and shot

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #6 (permalink)  
Old 03-08-10, 15:33
The_Duck The_Duck is offline
Registered User
 
Join Date: Jul 2003
Posts: 2,292
I've seen this before even in subqueries.
No table alias is specified for columns that are compared and the developers wonder why they are getting strange results.

there are many good reasons for table aliases and only one reason NOT to use aliases (laziness).

one very good reason is simply for a 3rd party to easily read and understand the code.
I frankly cannot stand someone sending me code to debug, and by looking at the code, I have no idea what columns belong to what tables.

also consider the fact that you possibly break any and all code if/when you add additional columns to tables. add the same name? have a join? welcome to a broken application (or just incorrect results in your application).
__________________
- The_Duck
you can lead someone to something but they will never learn anything ...
Reply With Quote
Reply

Tags
ora-00918, oracle 10g, oracle 11g

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On