[SQL ERROR 800]Corresponding types must be compatible in CASE expression.

SQL应用报错800.Corresponding types must be compatible in CASE expression.

错误描述:

  11:00:51  [SELECT - 0 row(s), 0.000 secs]  [Error Code: -800, SQL State: IX000]  Corresponding types must be compatible in CASE expression.

... 1 statement(s) executed, 0 row(s) affected, exec/fetch time: 0.000/0.000 sec  [0 successful, 0 warnings, 1 errors]

IBM解释:   

Cause

The data types of the THEN and ELSE part are different. For example the THEN part return a date value and the ELSE part return a date/time value.

Environment

Windows

Diagnosing the problem

Check your report for IF/THEN/ELSE expressions.

Resolving the problem

Verify your Impromptu report for IF/THEN/ELSE expressions. 
Check the data type of the THEN part with the data type of the ELSE part. Both need to be return the same data type. If not you need to add an additional calculation or a function to transform the result into a result with the required data type.

Exapmle:

IF ( column <> 1 ) THEN ( date ) ELSE ( date + 001 00:00:00:000 )

The THEN part returns a date value (data type: date)
The ELSE part returns a date/time value (data type: date/time)

Modify the above expression into:

IF ( column <> 1 ) THEN ( date + 000 00:00:00:000 ) ELSE ( date + 001 00:00:00:000 )

The THEN part returns a date/time value.
The ELSE part returns a date/time value.

or 
IF ( column <> 1 ) THEN ( date ) ELSE ( datetime-to-date ( date + 001 00:00:00:000 ) )

The THEN part returns a date value.
The ELSE part returns a date value.

参见:

http://www-01.ibm.com/support/docview.wss?uid=swg21425745


举例分析:


select  unique case when month(statdate) <10 then 0||month(statdate) else ''||month(statdate) end  statdate from  disxxx
where statdate = '20130731' or statdate = '20121231';
select  unique case when month(statdate) <10 then 0||month(statdate) else month(statdate) end  statdate from  disxxx
where statdate = '20130731' or statdate = '20121231'

0||month(statdate)  这个得到的 是一个字符串
month(statdate) 这个得到的是个 数字。

两个冲突!

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ORA-01790 错误是由于你在 UNION ALL 语句中选择的列的数据类型不匹配所导致的。在 UNION ALL 语句中,每个 SELECT 子句返回的列的数据类型必须与其他 SELECT 子句返回的列的数据类型相同。 你可以通过以下方法解决这个问题: 1. 确保每个 SELECT 子句返回的列的数量相同,并且每个列的数据类型相同。 2. 明确指定每个 SELECT 子句返回的列的数据类型,以确保它们匹配。例如,你可以使用 CAST 函数将列转换为正确的数据类型,如下所示: ``` INSERT INTO table_name (column1, column2, column3, ...) SELECT CAST(value1 AS VARCHAR2(50)), CAST(value2 AS NUMBER), CAST(value3 AS DATE), ... FROM table2 UNION ALL SELECT CAST(value4 AS VARCHAR2(50)), CAST(value5 AS NUMBER), CAST(value6 AS DATE), ... FROM table3 UNION ALL SELECT CAST(value7 AS VARCHAR2(50)), CAST(value8 AS NUMBER), CAST(value9 AS DATE), ... FROM table4; ``` 以上是一个示例,你需要将 CAST 函数中的数据类型替换为你实际使用的数据类型。 3. 如果你无法确保每个 SELECT 子句返回的列的数据类型相同,可以考虑使用 UNION ALL 的另一种形式,即 UNION ALL SELECT NULL AS column1, NULL AS column2, ... FROM DUAL,这样可以创建一个包含适当列的虚拟表,并使每个 SELECT 子句返回相同的列数和数据类型。如下所示: ``` INSERT INTO table_name (column1, column2, column3, ...) SELECT value1, value2, value3, ... FROM table2 UNION ALL SELECT value4, value5, value6, ... FROM table3 UNION ALL SELECT value7, value8, value9, ... FROM table4 UNION ALL SELECT NULL AS column1, NULL AS column2, NULL AS column3, ... FROM DUAL; ``` 以上是一个示例,你需要将 NULL AS column1, NULL AS column2, ... 替换为你实际使用的列名称。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值