reg10
reg10

Reputation: 191

Oracle empty conditions to check the ' ' condition

How do I compare a VARCHAR2 variable, which is an empty value?

Upvotes: 19

Views: 58917

Answers (2)

Ollie
Ollie

Reputation: 17538

You could use either of these:

IF v_test IS NULL
THEN
   -- Business Logic

or

IF NVL(v_test, 'NULL') = 'NULL'
THEN
   -- Business Logic

Your question does say "compare" a VARCHAR variable which is null so if you are comparing it to another variable then:

IF (v_test1 IS NULL and v_test2 IS NULL)
THEN
   -- Business Logic

That would check if they are both null.

Hope it helps...

Upvotes: 13

Karel Petranek
Karel Petranek

Reputation: 15154

Oracle doesn't differentiate between empty strings and NULL. To check if a variable is an empty string, use the IS NULL syntax.

Upvotes: 49

Related Questions