Answers:
甲骨文:
该null
文字不具有类型,但
null
可以强制转换为任何类型,当
控制decode
函数的返回类型,例如:
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
union
当第一个查询块包含一个null
null
存储在数据库中的值始终具有以下类型:
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')
-------------------------
1
SQL Server,int
SELECT NULL AS foo INTO dbo.bar
SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'bar'
DROP TABLE dbo.bar
MySQL,二进制(0)
CREATE TABLE mydb.foo (select NULL AS bar);
EXPLAIN mydb.foo;
DROP TABLE mydb.foo;
select isnumeric(null)
= 0 ...有趣
Oracle在某种意义上是某种字符串类型。
这就是ADO Reader告诉我的。这是一个Powershell脚本:
[System.Reflection.Assembly]::LoadWithPartialName("System.Data.OracleClient")
$ConnectionString = "Data Source=myTNS;User ID=myUSER;Password=myPassword"
$conn=new-object System.Data.OracleClient.OracleConnection
$conn.ConnectionString=$ConnectionString
$conn.Open()
$sql = "Select NULL xx from DUAL"
$cmd=new-object System.Data.OracleClient.OracleCommand($sql,$conn)
$r = $cmd.ExecuteReader()
$r.GetSchemaTable() | % { $_
}
那给
ColumnName : XX
ColumnOrdinal : 0
ColumnSize : 0
NumericPrecision : 0
NumericScale : 0
DataType : System.String
ProviderType : 22
IsLong : False
AllowDBNull : True
IsAliased :
IsExpression :
IsKey :
IsUnique :
BaseSchemaName :
BaseTableName :
BaseColumnName :
ProviderSpecificDataType : System.Data.OracleClient.OracleString
注意行
ProviderSpecificDataType:System.Data.OracleClient.OracleString
postgres:
create table foo as select null as bar;
WARNING: column "bar" has type "unknown"
DETAIL: Proceeding with relation creation anyway.
postgres=> \d foo
Column | Type | Modifiers
--------+---------+-----------
bar | unknown |