patternMinor
Does NULL have a type?
Viewed 0 times
typenullhavedoes
Problem
Various sources (eg Wikipedia, PSOUG) state that Oracle's
What about other RDBMSs?
null does not have a type. Is this true?What about other RDBMSs?
Solution
Oracle:
The
-
-
controlling the return type of the
-
The
null literal does not have a type, but-
null can be cast to any type, and this may be necessary when- calling overloaded procedures or functions
-
controlling the return type of the
decode function, eg:select decode('A','B',to_char(null),'A','1') from dual;
DECODE('A','B',TO_CHAR(NULL),'A','1')
-------------------------------------
1
select decode('A','B',to_number(null),'A','1') from dual;
DECODE('A','B',TO_NUMBER(NULL),'A','1')
---------------------------------------
1- controlling column types of set operators like
unionwhen the first query block includes anull
-
null values stored in the database always have a type:create table t(n integer, s varchar(10));
insert into t values(null, null);
select decode('A','B',n,'A','1') from t;
DECODE('A','B',N,'A','1')
-------------------------
1
select decode('A','B',s,'A','1') from t;
DECODE('A','B',S,'A','1')
-------------------------
1Code Snippets
select decode('A','B',to_char(null),'A','1') from dual;
DECODE('A','B',TO_CHAR(NULL),'A','1')
-------------------------------------
1
select decode('A','B',to_number(null),'A','1') from dual;
DECODE('A','B',TO_NUMBER(NULL),'A','1')
---------------------------------------
1create table t(n integer, s varchar(10));
insert into t values(null, null);
select decode('A','B',n,'A','1') from t;
DECODE('A','B',N,'A','1')
-------------------------
1
select decode('A','B',s,'A','1') from t;
DECODE('A','B',S,'A','1')
-------------------------
1Context
StackExchange Database Administrators Q#4412, answer score: 8
Revisions (0)
No revisions yet.