As you can see in the above syntax that NULLIF accepts only 2 parameters. If expr1 and expr2 are same then function returns NULL else expr1.
Parameters can be column name as well as any literal value. Also, expr1 can never be literal NULL and both parameters should be in same datatype.
Let’s do some examples as they always play a major part in understanding the concept.
You can see in the above code. expr1 and expr2 are same so function returned NULL.
This time expr1 and expr2 are not same so function returned expr1.
What if we put expr1 in number datatype and expr2 in char datatype.
So in this case, it returns an error. So expr1 and expr2 should always be in same datatype.
That’s it for NULLIF. If you have any questions/suggestions, please comment below or write me an email.