oracle数据库sql语句字符集不匹配错误,nvarchar2

1.问题

字符集不匹配
字符集不匹配错误
select pt.projectid, projectname, son.organname as constructioncompany,
case construction
when ‘1’ then ‘新建’
when ‘2’ then ‘续建’
when ‘3’ then ‘前期研究’
when ‘4’ then ‘预备’
end as construction, ndjsnr, to_char(scheduleddate, ‘yyyy-MM-dd’) as scheduleddate, to_char(estimatedendtime, ‘yyyy-MM-dd’) as estimatedendtime, totalinvestment
from project pt
left join sys_organization son

2.原因

在这里插入图片描述
关键字 when then else 后面的值的字符类型与字段 construction类型不一致,construction类型为nvarchar2,因此在比较时发生字符集不匹配错误。

3.解决方法

复杂方式:用to_char()函数将所有值改成同类型字符,string类型。
select pt.projectid, projectname, son.organname as constructioncompany,
case to_char(construction)
when to_char(‘1’) then to_char(‘新建’)
when to_char(‘2’) then to_char(‘续建’)
when to_char(‘3’) then to_char(‘前期研究’)
when to_char(‘4’) then to_char(‘预备’)
end as construction, ndjsnr, to_char(scheduleddate, ‘yyyy-MM-dd’) as scheduleddate, to_char(estimatedendtime, ‘yyyy-MM-dd’) as estimatedendtime, totalinvestment
from project pt
left join sys_organization son
on trim(pt.constructioncompany)=son.organid;
简单方式:用to_char()函数将字段construction变为string类型即可
select pt.projectid, projectname, son.organname as constructioncompany,
case to_char(construction)
when ‘1’ then ‘新建’
when ‘2’ then ‘续建’
when ‘3’ then ‘前期研究’
when ‘4’ then ‘预备’
end as construction, ndjsnr, to_char(scheduleddate, ‘yyyy-MM-dd’) as scheduleddate, to_char(estimatedendtime, ‘yyyy-MM-dd’) as estimatedendtime, totalinvestment
from project pt
left join sys_organization son
on trim(pt.constructioncompany)=son.organid;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值