During the Oracle storage test, it is found that the values of many columns in the product table may be null, resulting in not exists results inconsistent with
The test is as follows:
-- Construct two tables with the same table structure
SQL> desc t_null_column;
Name Type Nullable Default Comments
----------------------------------
A INTEGER Y
B INTEGER Y
C INTEGER Y
SQL> desc t_null_column_2;
Name Type Nullable Default Comments
----------------------------------
A INTEGER Y
B INTEGER Y
C INTEGER Y
-- Column B is null.
SQL> select * from t_null_column;
A B C
---------------------------------------------------------------------------------------------------------------------
1 2
SQL> select * from t_null_column_2;
A B C
---------------------------------------------------------------------------------------------------------------------
1 2
-- The following SQL statement is intended to query records that are not in the t_null_column_2 table at all. What I want is that records are not returned and records are returned.
SQL> select tc. * from t_null_column tc where not exists (select 1 from t_null_column_2 tc2 where tc. a = tc2.a and tc. B = tc2. B and tc. c = tc2.c );
A B C
---------------------------------------------------------------------------------------------------------------------
1 2
-- Modify the preceding SQL statement and nvl the null Column B. The result is as expected.
SQL> select tc. * from t_null_column tc where not exists (select 1 from t_null_column_2 tc2 where tc. a = tc2.a and nvl (tc. b, 1) = nvl (tc2. B, 1) and tc. c = tc2.c );
A B C
---------------------------------------------------------------------------------------------------------------------
Conclusion: 1. null is terrible and must be thoroughly understood. Otherwise, a big mistake will be made.
2. null and null are not equal, that is, the result of null = null is false rather than true.