A colleague encountered a problem today:
select 'true ' from dual where (1,2) not in ((2,3),(2,null));
select 'true ' from dual where (2,1) not in ((2,3),( 2,null));
the results of the above two examples are actually different
select 'true ' from dual where (2,1) not in ((2,3),( 2,null));
the results of the above two examples are actually different
in/not in uses the same method as =/ <> when judging NULL, that is, it must use is null to judge, otherwise it will always fail.
The statement
select 'true ' from dual where (1,2) not in ((2,3),(2,null));
The reason for success is that when judging the binary value, one of the non-null elements is first judged, and the element is successful or Failure "short-circuits" the other. Since the first element above makes not in successful, the second element is no longer processed. The first element of the
statement
select 'true ' from dual where (2,1) not in ((2,3),(2,null)); does not cause a "short circuit", so a null judgment is caused, so the result is always
fail.
Please re-experiment the statement
select 'true ' from dual where (2,1) not in ((2,3),(null,3));
the result is true because the second element short-circuits the first element.
The statement
select 'true ' from dual where (1,2) not in ((2,3),(2,null));
The reason for success is that when judging the binary value, one of the non-null elements is first judged, and the element is successful or Failure "short-circuits" the other. Since the first element above makes not in successful, the second element is no longer processed. The first element of the
statement
select 'true ' from dual where (2,1) not in ((2,3),(2,null)); does not cause a "short circuit", so a null judgment is caused, so the result is always
fail.
Please re-experiment the statement
select 'true ' from dual where (2,1) not in ((2,3),(null,3));
the result is true because the second element short-circuits the first element.