GBase 8s
适配迁移
文章

使用nvl2或者decode或者case报错,错误代码800

发表于2023-04-23 15:24:1473次浏览0个评论

问题描述:

使用nvl2或者decode或者case时,报“800: Corresponding data types must be compatible in CASE expression or DECODE function.”错误

 

解决方案:

800错误表示case或者decode的各个条件返回值需要一致或者是兼容的。

如下,col2为datetime year to second类型,两个条件的返回值:col2 + 1为datetime year to second,而to_date的返回值的类型是datetime year to fraction(5)。系统严格的认为两个并不一致,故而报800错误。

nvl2(col2, col1 + 1, to_date('2020-05-26 00:00:00','yyyy-mm-dd hh24:mi:ss'))

需将其改为一致:

nvl2(col2, 

to_date(to_char(col2 + 1,'yyyy-mm-dd hh24:mi:ss'),'yyyy-mm-dd hh24:mi:ss'), 

to_date('2020-05-26 00:00:00','yyyy-mm-dd hh24:mi:ss'))

-- 或者使用强制转换

nvl2(col2, 

col1 + 1, 

to_date('2020-05-26 00:00:00','yyyy-mm-dd hh24:mi:ss')::datetime year to second) 注: '::'表示转换后的类型

评论已关闭