Analysis on the non equal sign in Oracle

  • 2021-08-17 01:19:13
  • OfStack

About the non-equal sign in Oracle:
In Oracle,
< >
!=
~=
^=
They all mean not equal to the sign. Can be used.
But strangely yes, when I want to come up with an price that is not 180000: (price is Number type)
SELECT id, name FROM product where price < > 180000;
When this statement is executed, the record of priceis null will not appear. That is, you can't get price, which is the product of null. You must use:
SELECT id, name FROM product where price < > 180000 or price is null; Just do it.
The same problem exists with the fields of strings.
Remember that null can only be judged by is null or is not null, and other operators and null operations are false.
==============================================================
Test: select * from test where name < > 'xn'. Only name non-empty records can be found. Remove name < > 'xn' will do. There is something wrong with this writing.
Then instr (name, 'xn') = 0 is used to judge. If name is not empty, the judgment is still valid. If name is empty, this judgment goes wrong again. As a last resort, instr (concat (name, 'xx'), 'xn') = 0 is used to judge, because even if name is empty, it will not be empty when connected with 'xx'.
So the final sql statement is:
select * from test where instr (concat (name, 'xx'), 'xn') = 0 to query records where the name field is not equal to 'xn'.
Or you can use select * from test where nvl (name, 'xx') < > 'xn' to query records whose name field is not equal to 'xn'.


Related articles: