What is the datatype for NULL
when passing that value for no data into a database?
13 Answers
There is NO data type of NULL. NULL itself means ABSENCE of data. When there is no data, how can it have type?

- 19,486
- 24
- 91
- 127
-
1Yeah, this is what I had to be taught when I joined my company. NULL is the absence, it is not a type, however it can be represented by types (i.e. the .NET framework has DBNull.Value as a representation of the NULL value). – Kieran Senior Jun 26 '09 at 11:11
-
1Yes I agree. In any technology you must have *something* to represent it. (You cant represent nothing with nothing). But as a concept, NULL means "nothing". Literally! – Hemant Jun 26 '09 at 11:15
-
@Hemant, while that is a good database definition of NULL, that abstract concept is represented by an actual value. Assuming that Prabhahar wants to pass the value in some programming language to the database, there will be an associated database driver API which will have an implementation of passing NULL. – MAbraham1 Jul 22 '16 at 18:02
-
I don't agree that Null means "an absence of a value". Rather, it is a special value (in addition to any ordinary possible value associated with the datatype) which is subject to special logic and handling. It is possible to explicitly record that a normal input to the computer system was not available at the time the record was made - and that record is then a present record with a present Null value. – Steve Aug 20 '22 at 08:55
Null does not have a specific data type in SQL. Any nullable column or variable can contain null. Null is never equal or unequal to anything. You can cast a variable holding null to another variable and get null, for example:
declare @a integer
set @a = null
select convert (float, @a)
----------------------
NULL
(1 row(s) affected)

- 64,444
- 15
- 143
- 197
Usually NULL is its own datatype - the type of 1 is "INTEGER", the type of the type of NULL is "NULL"

- 316,276
- 54
- 369
- 333
Datatype for NULL
is as meaningless as datatype for 0
: it can be INTEGER
, FLOAT
or a VARCHAR
. You cannot tell it just from the value.
NULL
is legitimate value in almost every datatype domain, which means the absence of actual value.
It's also meaningless to discuss datatypes out of context of certain RDBMS
.
In SQLite
, for instance, datatypes are value-bound, not column-bound, and NULL
is a first-class datatype per se.
In Oracle
, the datatypes are more strictly defined. For instance, this query works:
SELECT COALESCE(dt, i)
FROM (
SELECT CAST(NULL AS DATE) AS dt, CAST(NULL AS DATE) i
FROM dual
) q
and this does not:
SELECT COALESCE(dt, i)
FROM (
SELECT CAST(NULL AS DATE) AS dt, CAST(NULL AS NUMBER) i
FROM dual
) q
, because the latter query returns two columns of different datatypes, both of them having values of NULL
, and COALESCE
requires both arguments to have same datatype.
It's better to say that a NULL
of any datatype can be implicitly converted to a NULL
on another datatype.
For instance, a VARCHAR
can be implicitly converted to a INTEGER
if it has value of 0
, but cannot if it has value of 'some_string'
.
For NULL
's, any datatype can be implicitly converted to any other datatype, if the implicit conversion between them is allowed at all.

- 413,100
- 91
- 616
- 614
In SQL a NULL is a "mark" (something other than a value) that can apply to any SQL type. So it is orthogonal to type.

- 24,981
- 1
- 44
- 82
NULL is the value for 'undefined'. So any type in a database can be 'undefined', as it's a property of the column: a value of a row for the specific column can be 'undefined' which means it's 'NULL', no matter what the type is. As long as the column is nullable.

- 8,259
- 1
- 27
- 28
I think the question defeats itself. If NULL had a datatype, wouldn't you be forced to change it with every instantiation outside of its default. For example, when you create it as a character, but then force it into an object's value?
NULL==NULL
That is all.

- 336
- 3
- 12
-
At risk of being contrary, most platforms that fully support null would return NULL to the comparison "NULL == NULL", not in fact true :) This makes your above comparison invalid, as _any_ comparison with NULL is meaningless, except checking if it's null with ...IS NULL – Jeremy Smyth Jun 26 '09 at 11:58
-
This made me smile, and I see what you're saying. Chalk one up for learning something **new** everyday. – bobby Jun 27 '09 at 00:42
Actually, in PowerShell comparing $null -eq $null gives False. Also, -not $null will give you True, so here it seems to be reprezented as False. I know, PowerShell might not be a good example, but still :)

- 648
- 6
- 12
Usually SQL NULL
does not have a type associated with it. However there are exceptions. Database engines postgresql and derby (javadb) require that null has a type. In other words they do not support untyped null. So query conditions like NULL IS NULL
may fail. Here, NULL
must be given a type, the expected type of the target that processes the NULL
value. In this case this appears silly because there is no target and this can be counterproductive.
See CAST function: -- you must cast NULL as a data type to use it
See Queries with guarded null Parameter fail and Add support for setObject(arg, null)
Please vote for these issues so that the odd database engines change their ways.

- 1,163
- 1
- 15
- 24
Prabhahar, each type of database driver has its own way of handling NULL
. You will have to examine the driver API for the specific database.
For example if you are using the Java Derby database, simply pass in the Java native type, null as shown in Ian Bjorhovde's answer to "Derby's Handling of NULL Values":
insert into T_AUTHOR (
ID, FIRST_NAME, LAST_NAME,
DATE_OF_BIRTH, YEAR_OF_BIRTH, ADDRESS)
VALUES (
1000, 'Lukas', 'Eder',
'1981-07-10', null, null
);
Here is another null
example of JDBC:Inserting null to Integer column:
pst.setNull(4, java.sql.Types.INTEGER);
NULL
can be cast (converted) to any data type yet data type comparisons with NULL
always return FALSE
.

- 4,742
- 10
- 44
- 52
-
1-1, because comparisons with NULL result in NULL not in FALSE. In an IF statement in PL/SQL, NULL is treated like FALSE, but NOT NULL is NULL, not TRUE – Erich Kitzmueller Jun 26 '09 at 11:25
-
1