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.
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.
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.
There is NO data type of NULL. NULL itself means ABSENCE of data. When there is no data, how can it have type?
Usually NULL is its own datatype - the type of 1 is "INTEGER", the type of the type of NULL is "NULL"
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.
NULL
can be cast (converted) to any data type yet data type comparisons with NULL
always return FALSE
.
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.
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)
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 :)