对于null通过函数进行转换
字符串(varchar): COALESCE( 字段名,'')
金额(DECIMAL): COALESCE( 字段名,0.00)
整数(BIGINT): COALESCE( 字段名,0)
时间: COALESCE(to_char(字段名,'yyyy-mm-dd hh34:mi:ss'),'1900-12-31 00:00:00')
date类型默认赋值'1900-12-31', time类型默认赋值 '00:00:00',timestamp类型默认赋值'1900-12-31 00:00:00'
例如:
FEE DECIMAL,
TOTAL_COUNT BIGINT,
SNAPSHOT_DATE date,
PLATFORM_SIGN varchar
如果在查询中存在空值,而我不想出现空值,这时就需要转换一下,(时间类型根据业务需求来,有的默认不一样)
select COALESCE(to_char(SNAPSHOT_DATE,'yyyy-mm-dd'),'1900-12-31') from 表名;
select COALESCE(TOTAL_COUNT,0) from 表名;
select COALESCE(FEE,0.00) from 表名;
select COALESCE(PLATFORM_SIGN,'') from 表名;
网站栏目:COALESCE函数
转载注明:
http://bjjierui.cn/article/gphsgj.html