tags:

views:

422

answers:

10
+1  Q: 

Data type of NULL

Can anybody let me know that what is the datatype for NULL?

Some body is tellin that NULL doesnt hav any data type. some body is telling that NULL is Character type.

Please let me know that what is the datatype of NULL.

Thanks in advance.

A: 

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.

Frans Bouma
A: 

I think DBNULL or NULL is a special type.

pho3nix
+6  A: 

There is NO data type of NULL. NULL itself means ABSENCE of data. When there is no data, how can it have type?

Hemant
Yeah, 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).
Kezzer
Yes 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
A: 

Usually NULL is its own datatype - the type of 1 is "INTEGER", the type of the type of NULL is "NULL"

Greg
A: 

http://en.wikipedia.org/wiki/Null_(SQL)

Fermin
A: 

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.

bobby
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
This made me smile, and I see what you're saying. Chalk one up for learning something **new** everyday.
bobby
A: 

NULL can be cast (converted) to any data type yet data type comparisons with NULL always return FALSE.

CannibalSmith
-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
ammoQ
the same goes for WHERE clauses etc.
ammoQ
+1  A: 

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.

Quassnoi
+2  A: 

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)
ConcernedOfTunbridgeWells
A: 

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 :)

bodunbodun