I have this table where NULL is the NULL
value, not the string NULL:
MYCOL
--------
NULL
example
Why does this query not return the NULL
row?
select * from example_so where nvl(mycol, '') = '';
I have this table where NULL is the NULL
value, not the string NULL:
MYCOL
--------
NULL
example
Why does this query not return the NULL
row?
select * from example_so where nvl(mycol, '') = '';
''
is again NULL
in Oracle, because Oracle doesn't support empty Strings just like Other High Level languages or DBMS..
You need to look for NULL/empty string using IS NULL
or IS NOT NULL
No other relational operator work against NULL
, though it is syntactically valid. SQLFiddle Demo
It has to be,
select * from example_so where mycol IS NULL
EDIT: As per Docs
Oracle Database currently treats a character value with a length of zero as null. However, this may not continue to be true in future releases, and Oracle recommends that you do not treat empty strings the same as nulls.
NULL
. It is quite touchy though. –
Durative UNKNOWN
.. the docs I referred here show the same. –
Walworth AND
and OR
can be used with NULL
to give useful (that is not NULL
) results. –
Durative OR
will suppress any index usage. –
Entanglement NULL
. But the DB does. But might change in the future. But we don't know when. And you can't control or change the behavior. But don't treat them the same." –
Bullate Because NULL = NULL
is simply unknown. A third state perhaps? It is neither TRUE
nor FALSE
.
Oracle considers an EMPTY STRING as NULL.
nvl(mycol, '')
makes no real sense, as you are making the NULL back to NULL and comparing it again with NULL.
SQL> WITH DATA AS(
2 SELECT 1 val, 'NULL' str FROM dual UNION ALL
3 SELECT 2, NULL str FROM dual UNION ALL
4 SELECT 3, '' str FROM dual UNION ALL
5 SELECT 4, 'some value' str FROM dual)
6 SELECT val, NVL(str, 'THIS IS NULL') FROM data WHERE str IS NULL
7 /
VAL NVL(STR,'THI
---------- ------------
2 THIS IS NULL
3 THIS IS NULL
SQL>
select * from example_so where nvl(mycol, '') = '';
nvl(mycol, '') will be resulted as NULL and when you compared NULL with empty string it cant be compared
create table t(id varchar2(2));
insert into t values (nvl(null,'')); <------ this will insert NULL
insert into t values (nvl(null,'et'));
© 2022 - 2024 — McMap. All rights reserved.
''
isNULL
? Isn’t''
the empty string? – Durative