What is the correct way of checking if varchar2 is empty? What is the correct way of checking if varchar2 is empty? oracle oracle

What is the correct way of checking if varchar2 is empty?


Assuming that you are using varchar2 throughout your code, l_version is null will be future proof.

Oracle created the varchar2 data type when the ANSI standards declared that varchar should treat NULL and the empty string as separate entities. The intention was that the behavior of the varchar2 data type would remain consistent going forward while varchar in the future could use the new standard NULL comparison semantics. Of course, today varchar and varchar2 are synonyms for each other and they have been for at least a couple of decades so the odds that Oracle actually changes the behavior of the varchar data type in the future is pretty low.

When you look at the documentation for the VARCHAR2 and VARCHAR data types, it talks about the comparison semantics for VARCHAR potentially changing in the future. Unfortunately, it's not explicit that the comparison semantics they're talking about are the equivalence (or lack thereof) between NULL and the empty string. But since VARCHAR is an ANSI standard data type and the only difference in VARCHAR comparison semantics between Oracle and the ANSI standard is whether the empty string is NULL, that's the generally accepted interpretation.

Do not use the VARCHAR datatype. Use the VARCHAR2 datatype instead. Although the VARCHAR datatype is currently synonymous with VARCHAR2, the VARCHAR datatype is scheduled to be redefined as a separate datatype used for variable-length character strings compared with different comparison semantics.


If the behaviour does change then are you not going to want to be able to distinguish between empty string and null when such a thing is possible? In other words, future proof code that treats empty strings and nulls as the same will probably need revisiting in the future anyway.

Also, there are currently something like 100 billion trillion null strings stored in Oracle databases worldwide that will continue to be null.

So my advice is to forget about it, and just use IS NULL.


Sounds like a lawyer got into Oracle's documentation. I can't imagine in a million years that Oracle would suddenly change how they handle empty strings with varchar2, a TON of code would break (and much of it silently). This statement in the docs seems to be a "cover your a$$" just in case. So, just continue to use "is null" and don't worry. If anything, they'll change varchar behavior, not varchar2.

My 2 cents anyway.