'字符集不匹配' CASE语句中的错误

时间:2014-08-06 17:50:03

标签: sql oracle

我试图让Oracle case语句的else部分返回一个set字符串值; Field1是NVARCHAR2(255 CHAR)

select case when substr(field1, 10, 1) = 'x' 
         then substr(field1, 9, 3) 
         else '---'
       end Data
  from table a

数据示例

Row       field1
1         Current 1x1 Cost
2         Current Cost 
3         Current 1x1 Efficiency
4         Current Efficiency
5         Current 1x1 CostB
6         Current CostB

我想要回归

Row       Data
1         1x1
2         ---
3         1x1
4         ---
5         1x1
6         ---

1 个答案:

答案 0 :(得分:2)

尝试将---投射到NVARCHAR2,如下所示

select case when substr(field1, 10, 1) = 'x' 
         then substr(field1, 9, 3) 
         else cast('---' as NVARCHAR2(255))
       end Data
  from tab a

现在,evry值返回相同类型的数据

Sql Fiddle Demo