OUTER JOIN BETWEEN MULTIPLE COLUMNS - ONE COLUMN MAY BE NULL ON BOTH SIDES
236779Apr 3 2006 — edited Apr 3 2006Dear Sirs:
I would like to know whether You can suggest any workaround for a problem I am experiencing with outer joins in Oracle.
I need to select from two tables in outer join. The join is across four columns: i noticed that whenever one of the four columns is null ON BOTH SIDES the query doesn't return anything from the joined table (see row 2 in both tables from the following example)
TableA
ROW 1 = col1: '123', col2 'ABC', col3 '456', col4 'DEF'
ROW 2 = col1: '234', col2 'GHI', col3 '567', col4 null
ROW 3 = col1: '456', col2 'LMN', col3 '890', col4 'OPQ'
TableB
ROW 1 = col 1: '123', col 2 'ABC', col 3 '456', col 4 'DEF', col5 = 'FIRST_VALUE'
ROW 2 = col 1: '234', col 2 'GHI', col 3 '567', col 4 null, col5 = 'SECOND_VALUE'
ROW 3 = col 1: '999', col 2 'ZZZ', col 3 '999', col 4 'ZZZ', col5 = 'THIRD_VALUE'
SAMPLE STATEMENT:
Select tableA.col1,tableA.col2,tableA.col3,tableA.col4,tableB.col5
from tableA, tableB
where ( tableA.col1=tableB.col1(+) and tableA.col2=tableB.col2(+) and tableA.col3=tableB.col3(+) and tableA.col4=tableB.col4(+) )
Results:
'123','ABC','456','DEF', 'FIRST_VALUE'
'234','GHI','567',null, null <=== Here, I expected 'SECOND_VALUE' instead!!
'456', 'LMN', '890','OPQ', null
I suspected that this was an oracle feature, and in fact even the simplest single-column outer join behaves the same way.
Create table TABLE1 (name varchar2(10), mycode varchar2(10));
Create table TABLE2 (surname varchar2(10), mycode varchar2(10));
insert into TABLE1 values ('CESARE', null);
insert into TABLE2 values ('BRIZIO', null);
This statement:
Select name, surname from TABLE1,TABLE2 where TABLE1.mycode = TABLE2.mycode(+);
Returns:
name = 'CESARE', surname = null.
Thank you for Your attention.
Cesare Brizio