Oracle SQL_Null Related functions-3_NULLIF

NULLIF

admin Functions, Oracle ,

Hi Aliens,
Today, we will talk about another Null Related Function, NULLIF.
You can read my notes on NVL, NVL2 and COALESCE. Please have a look if you haven’t yet.

Syntax:

NULLIF(expr1, expr2)

NULLIF:
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.

Example-1

You can see in the above code. expr1 and expr2 are same so function returned NULL.

Example-2

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.

Example-3

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.

If you like this blog, do share with your friends and colleagues on your social media.
For more updates join my facebook group and do like my facebook page.

Thank you,
Kapil Kumar
dbgeek.in

Sharing is caring!

You May Also Like..

WHERE

SQL – WHERE clause

Hi DBgeek Army, Welcome back to the world of Oracle! Where clause helps to select desired rows or helps to […]

comments

Comment in SQL and PL-SQL

Hi DBgeek Army, Welcome back to the world of Oracle! Comments are very important aspects of our code. No matter […]

merge

SQL – MERGE Statement

Hi Devs, As we have already learned INSERT INTO and UPDATE statement, our next very important statement is MERGE. Merge […]

Leave a Reply

Your email address will not be published. Required fields are marked *