I'm doing an update to a temp table in Oracle. My thinking was that I could use NVL to set a value ( essentially making the null value on either side equal )
What happens in the update is that if a number of comparisons hold true then a column is not updated, one of those compared columns can be null and Oracle does not compare null values.
The Code may make it easier to understand.
UPDATE Temp_Table A Set T.ColZ = 'something'
WHERE NOT EXISTS
( SELECT * FROM Temp_Table B
WHERE A.ColF = B.ColF
AND ...more column comparisons
AND ((NVL(A.ColC, 'N/A') = NVL(B.ColC, 'N/A'))
AND more column Comparisons)
);
The update works when ColC contains no Nulls but when I have a row that ColC is Null then it gets updated despite being the same on both sides.
I had also tried using a subquery in the where clause but with no luck. Would a subquery be a better method to use here?
Any help or hints are greatly appreciated.
Just wanted to add that ideally I would like to skip the comparison altogether if that col is null so any ideass on how to do it that way are welcome. Thanks
A per Ypers request an example with a few rows... hopefully it is clear enough
Temp_Table
Col1 | Col2 | Col3 | Col4 |Col5 |Col6
AB | DC | EF | GH | 08 |
BA | CD | EF | GH | 08 |
AB | DC | HI | NULL| 05 |
AB | DC | JK | LM | 04 |
In the above table row 1 matches with row 2. My update is supposed to single out rows like 3 and 4 where there is no corresponding row. I can get it to work when Col4 is not Null but it fails when that value is Null. Just FYi in the temp_table any Col2 that has DC value Col1 will have AB as its value and the for any CD value in Col2 then Col1 has BA as its value.
UPDATE Temp_Table T SET Col6 = 'Unmatched'
WHERE NOT EXISTS
( SELECT * FROM Temp_Table B
WHERE T.Col3 = B.Col3
AND T.COl4 = B.Col4
AND T.COl5 = B.Col5 )
Hope that helps and thanks.