Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Why the heck is (expr <> '') allowed?

575531May 2 2007 — edited May 6 2007
Peace be with you all!

Ok, after years of dealing with SQL Server, I'm learning a real db - Oracle 9i. I didn't
know that a stored procedure lang could be a real programming language. PL/SQL is
so very nice, but there is what appears to me to be a huge problem.

I now know that the empty string, '', is treated as null when used in an assignment
statement. What I can't understand is why these expressions are allowed by the
compiler as they will always evaluate to false:

expr = ''
expr <> ''
expr != ''

Am I missing something, or is there no possible semantic purpose for any of these
comparisons? Why does this not generate a compilation error?

And one last thing: I'm always (for now) dealing with these in the context of the
varchar2 type, not the fixed-width char types, although it doesn't seem to me
that the result would be any different, though it seems possible that the '' could
be interpreted differently if the LHS of the comparison evals to a fixed-width
char type.

Thanks in advance,
Robert McCall
Lasting peace & happiness for ALL non-violent human beings.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 3 2007
Added on May 2 2007
17 comments
835 views