Home » SQL & PL/SQL » SQL & PL/SQL » Wrong results with combination of Boolean, Left Join and To_Char (Oracle 12c, Windows Server 2012)
icon5.gif  Wrong results with combination of Boolean, Left Join and To_Char [message #639500] Wed, 08 July 2015 13:04 Go to next message
RFoersterj
Messages: 4
Registered: July 2015
Junior Member
Hi dear Forum-members,

we've got a strange behaviour of our Oracle 12c database:

We've got 2 tables, one containing informations about orders and another one that contains additional Information about those orders (so the relationship is a 1:1 relation).

When I run this specific query on our database, it won't give me back any values for the field CFISDEPOT (all results are null altough it is a boolean field that contains 1), but it should.

SELECT b.cfisdepot, 
       b.cfdepotkennung, 
       To_char(a.vonlieferdatumzeit, 'ddmmyyyy'), 
       To_char(a.vonlieferdatumzeit, 'ddmmyyyy') 
FROM   asendung a 
       LEFT JOIN abusinesspartnercustomfieldv b 
              ON a.absnr = b.id   


The explain plan Shows the following:

PLAN_TABLE_OUTPUT                                                                                                                                                                                                                                                                                          
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Plan hash value: 388152569                                                                                                                                                                                                                                                                                   
                                                                                                                                                                                                                                                                                                             
------------------------------------------------------------------------------------------------------                                                                                                                                                                                                       
| Id  | Operation             | Name                         | Rows  | Bytes | Cost (%CPU)| Time     |                                                                                                                                                                                                       
------------------------------------------------------------------------------------------------------                                                                                                                                                                                                       
|   0 | SELECT STATEMENT      |                              |   483K|    17M| 37176   (1)| 00:00:02 |                                                                                                                                                                                                       
|*  1 |  HASH JOIN RIGHT OUTER|                              |   483K|    17M| 37176   (1)| 00:00:02 |                                                                                                                                                                                                       
|   2 |   TABLE ACCESS FULL   | ABUSINESSPARTNERCUSTOMFIELDV |   626 | 15024 |    11   (0)| 00:00:01 |                                                                                                                                                                                                       
|   3 |   TABLE ACCESS FULL   | ASENDUNG                     |   483K|  6138K| 37164   (1)| 00:00:02 |                                                                                                                                                                                                       
------------------------------------------------------------------------------------------------------                                                                                                                                                                                                       
                                                                                                                                                                                                                                                                                                             
Query Block Name / Object Alias (identified by operation id):                                                                                                                                                                                                                                                
-------------------------------------------------------------                                                                                                                                                                                                                                                
                                                                                                                                                                                                                                                                                                             
   1 - SEL$0E991E55                                                                                                                                                                                                                                                                                          
   2 - SEL$0E991E55 / B@SEL$1                                                                                                                                                                                                                                                                                
   3 - SEL$0E991E55 / A@SEL$1                                                                                                                                                                                                                                                                                
                                                                                                                                                                                                                                                                                                             
Predicate Information (identified by operation id):                                                                                                                                                                                                                                                          
---------------------------------------------------                                                                                                                                                                                                                                                          
                                                                                                                                                                                                                                                                                                             
   1 - access("A"."ABSNR"="B"."ID"(+))                                                                                                                                                                                                                                                                       
                                                                                                                                                                                                                                                                                                             
Column Projection Information (identified by operation id):                                                                                                                                                                                                                                                  
-----------------------------------------------------------                                                                                                                                                                                                                                                  
                                                                                                                                                                                                                                                                                                             
   1 - (#keys=1) ROWID[ROWID,10], "B"."CFISDEPOT"[NUMBER,22], "B"."CFISDEPOT"[NUMBER,22],                                                                                                                                                                                                                    
       "B"."CFDEPOTKENNUNG"[VARCHAR2,1020], "A"."VONLIEFERDATUMZEIT"[DATE,7]                                                                                                                                                                                                                                 
   2 - ROWID[ROWID,10], "B"."ID"[NUMBER,22], "SYS_NC00022$"[RAW,126],                                                                                                                                                                                                                                        
       "B"."CFISDEPOT"[NUMBER,22], "B"."CFDEPOTKENNUNG"[VARCHAR2,1020], "B"."CFISDEPOT"[NUMBER,22]                                                                                                                                                                                                           
   3 - "A"."ABSNR"[NUMBER,22], "A"."VONLIEFERDATUMZEIT"[DATE,7]                                                                                                                                                                                                                                              

 31 Zeilen gewählt




When I remove one of the To_Char Statements, it works perfectly fine. Also it works fine when I change the left join to an inner join.

Have you ever experienced such a behaviour? The strange thing is that when I run this
query on our development-database, it works!

I compared all parameters of those two machines (SPFILE) and I could
figure out that the only differences are the nls_territory setting (on our production-box it's set to "Germany", on the
Dev-Box it's set to "Austria") and the allocated memory.

Thank you very much in advance for your help! Please let me know if you need any more Information.

-Robert

[Updated on: Wed, 08 July 2015 13:17]

Report message to a moderator

Re: Wrong results with combination of Boolean, Left Join and To_Char [message #639502 is a reply to message #639500] Wed, 08 July 2015 13:44 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
please post CREATE TABLE statements for both tables
Re: Wrong results with combination of Boolean, Left Join and To_Char [message #639503 is a reply to message #639500] Wed, 08 July 2015 15:36 Go to previous messageGo to next message
John Watson
Messages: 8929
Registered: January 2010
Location: Global Village
Senior Member
Your query states LEFT JOIN but the plan is RIGHT JOIN. Can you check that the CBO really did do that re-write? Not a mistake somewhere?

[Updated on: Wed, 08 July 2015 15:37]

Report message to a moderator

Re: Wrong results with combination of Boolean, Left Join and To_Char [message #639504 is a reply to message #639503] Wed, 08 July 2015 18:11 Go to previous messageGo to next message
Solomon Yakobson
Messages: 3273
Registered: January 2010
Location: Connecticut, USA
Senior Member
John Watson wrote on Wed, 08 July 2015 16:36
Your query states LEFT JOIN but the plan is RIGHT JOIN. Can you check that the CBO really did do that re-write? Not a mistake somewhere?


This is because optimizer decided to start with abusinesspartnercustomfieldv and right join it to asendung.

SY.
Re: Wrong results with combination of Boolean, Left Join and To_Char [message #639513 is a reply to message #639504] Thu, 09 July 2015 01:31 Go to previous messageGo to next message
RFoersterj
Messages: 4
Registered: July 2015
Junior Member
Attached, please find the SQL for creating the table ASENDUNG (without creation of Triggers and index)
  • Attachment: ASENDUNG.txt
    (Size: 26.60KB, Downloaded 1352 times)
Re: Wrong results with combination of Boolean, Left Join and To_Char [message #639514 is a reply to message #639513] Thu, 09 July 2015 01:32 Go to previous messageGo to next message
RFoersterj
Messages: 4
Registered: July 2015
Junior Member
Attached, please find the SQL for creating the table abusinesspartnercustomfieldv
Re: Wrong results with combination of Boolean, Left Join and To_Char [message #639578 is a reply to message #639514] Fri, 10 July 2015 09:25 Go to previous messageGo to next message
sandeep_orafaq
Messages: 88
Registered: September 2014
Member
Can you also provide the insert statements for test data?
Re: Wrong results with combination of Boolean, Left Join and To_Char [message #639838 is a reply to message #639578] Fri, 17 July 2015 10:06 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
It appears that OP is a write once, return never individual.
Re: Wrong results with combination of Boolean, Left Join and To_Char [message #639844 is a reply to message #639838] Fri, 17 July 2015 12:11 Go to previous message
RFoersterj
Messages: 4
Registered: July 2015
Junior Member
Hi,

I'm really sorry for my late reply. As it's currently holiday-season I'm filling in other Jobs.

I'll provide test data next week.

Thank you for your patience!

-Robert
Previous Topic: How to retrieve parent and child in different columns when they exist in a single column.
Next Topic: 25% lowest sal
Goto Forum:
  


Current Time: Fri Apr 19 00:13:01 CDT 2024