Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle empty conditions to check the ' ' condition

Tags:

sql

null

oracle

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

like image 230
reg10 Avatar asked Aug 27 '11 14:08

reg10


People also ask

Is null or empty check in Oracle?

Introduction to the Oracle IS NULL operator NULL is special in the sense that it is not a value like a number, character string, or datetime, therefore, you cannot compare it with any other values like zero (0) or an empty string (”).

Is null in Oracle where clause?

Here is an example of how to use the Oracle IS NULL condition in a SELECT statement: SELECT * FROM suppliers WHERE supplier_name IS NULL; This Oracle IS NULL example will return all records from the suppliers table where the supplier_name contains a null value.

How do you check if a table is empty in Oracle?

Use the IS [NOT] EMPTY conditions to test whether a specified nested table is empty, regardless whether any elements of the collection are NULL . The condition returns a boolean value: TRUE for an IS EMPTY condition if the collection is empty, and TRUE for an IS NOT EMPTY condition if the collection is not empty.

Is Empty function in Oracle?

IS EMPTY function. The IS EMPTY function provides an alternative syntax to IS_EMPTY and also returns TRUE if that set is empty. where set is a set of any set data type, such as a multi-assign double attribute. The results of this example would the same as the previous IS_EMPTY example.


2 Answers

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

like image 181
Karel Petranek Avatar answered Oct 06 '22 07:10

Karel Petranek


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

like image 28
Ollie Avatar answered Oct 06 '22 07:10

Ollie