Oracle数据库中,使用case语句,遇到VARCHAR2与NVARCHAR2问题
Posted zhxb
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Oracle数据库中,使用case语句,遇到VARCHAR2与NVARCHAR2问题相关的知识,希望对你有一定的参考价值。
问题:
在有sqlserver数据库迁移至Oracle数据库时,遇到将VARCHAR2付给NVARCHAR2问题
原sql
CASE A .kindCode
WHEN ‘2321034‘ THEN ‘02049‘ WHEN ‘2321035‘ THEN ‘11067‘ WHEN ‘2321022‘ THEN ‘11067‘ WHEN ‘2321039‘ THEN ‘02049‘
WHEN ‘2321041‘ THEN ‘10064‘ WHEN ‘2321030‘ THEN ‘10047‘ WHEN ‘2321031‘ THEN ‘10048‘ WHEN ‘2321032‘ THEN ‘02049‘
WHEN ‘2321033‘ THEN ‘02049‘ WHEN ‘2321001‘ THEN ‘11030‘ WHEN ‘2321002‘ THEN ‘10039‘ WHEN ‘2321003‘ THEN ‘10040‘
WHEN ‘2321004‘ THEN ‘10041‘ WHEN ‘2321005‘ THEN ‘10042‘ WHEN ‘2321006‘ THEN ‘02017‘ WHEN ‘2321007‘ THEN ‘02049‘
WHEN ‘2321008‘ THEN ‘02049‘ WHEN ‘2321009‘ THEN ‘11067‘ WHEN ‘2321010‘ THEN ‘11067‘ WHEN ‘2321011‘ THEN ‘11067‘
WHEN ‘2321017‘ THEN ‘02049‘ WHEN ‘2321018‘ THEN ‘02049‘ WHEN ‘2321019‘ THEN ‘02049‘ WHEN ‘2321020‘ THEN ‘04029‘
WHEN ‘2321021‘ THEN ‘02049‘ WHEN ‘2321025‘ THEN ‘02049‘ WHEN ‘2321040‘ THEN ‘02049‘ WHEN ‘2321016‘ THEN ‘02049‘
ELSE ‘2312‘ END AS CLASSESCODE,
修改后
CASE A .kindCode
WHEN CAST(‘2321034‘ as nvarchar2(10)) THEN CAST(‘02049‘as nvarchar2(10)) WHEN CAST(‘2321035‘ as nvarchar2(10)) THEN CAST(‘11067‘as nvarchar2(10))
WHEN CAST(‘2321022‘ as nvarchar2(10)) THEN CAST(‘11067‘as nvarchar2(10)) WHEN CAST(‘2321039‘ as nvarchar2(10)) THEN CAST(‘02049‘as nvarchar2(10))
WHEN CAST(‘2321041‘ as nvarchar2(10)) THEN CAST(‘10064‘as nvarchar2(10)) WHEN CAST(‘2321030‘ as nvarchar2(10)) THEN CAST(‘10047‘as nvarchar2(10))
WHEN CAST(‘2321031‘ as nvarchar2(10)) THEN CAST(‘10048‘as nvarchar2(10)) WHEN CAST(‘2321032‘ as nvarchar2(10)) THEN CAST(‘02049‘as nvarchar2(10))
WHEN CAST(‘2321033‘ as nvarchar2(10)) THEN CAST(‘02049‘as nvarchar2(10)) WHEN CAST(‘2321001‘ as nvarchar2(10)) THEN CAST(‘11030‘as nvarchar2(10))
WHEN CAST(‘2321002‘ as nvarchar2(10)) THEN CAST(‘10039‘as nvarchar2(10)) WHEN CAST(‘2321003‘ as nvarchar2(10)) THEN CAST(‘10040‘as nvarchar2(10))
WHEN CAST(‘2321004‘ as nvarchar2(10)) THEN CAST(‘10041‘as nvarchar2(10)) WHEN CAST(‘2321005‘ as nvarchar2(10)) THEN CAST(‘10042‘as nvarchar2(10))
WHEN CAST(‘2321006‘ as nvarchar2(10)) THEN CAST(‘02017‘as nvarchar2(10)) WHEN CAST(‘2321007‘ as nvarchar2(10)) THEN CAST(‘02049‘as nvarchar2(10))
WHEN CAST(‘2321008‘ as nvarchar2(10)) THEN CAST(‘02049‘as nvarchar2(10)) WHEN CAST(‘2321009‘ as nvarchar2(10)) THEN CAST(‘11067‘as nvarchar2(10))
WHEN CAST(‘2321010‘ as nvarchar2(10)) THEN CAST(‘11067‘as nvarchar2(10)) WHEN CAST(‘2321011‘ as nvarchar2(10)) THEN CAST(‘11067‘as nvarchar2(10))
WHEN CAST(‘2321017‘ as nvarchar2(10)) THEN CAST(‘02049‘as nvarchar2(10)) WHEN CAST(‘2321018‘ as nvarchar2(10)) THEN CAST(‘02049‘as nvarchar2(10))
WHEN CAST(‘2321019‘ as nvarchar2(10)) THEN CAST(‘02049‘as nvarchar2(10)) WHEN CAST(‘2321020‘ as nvarchar2(10)) THEN CAST(‘04029‘as nvarchar2(10))
WHEN CAST(‘2321021‘ as nvarchar2(10)) THEN CAST(‘02049‘as nvarchar2(10)) WHEN CAST(‘2321025‘ as nvarchar2(10)) THEN CAST(‘02049‘as nvarchar2(10))
WHEN CAST(‘2321040‘ as nvarchar2(10)) THEN CAST(‘02049‘as nvarchar2(10)) WHEN CAST(‘2321016‘ as nvarchar2(10)) THEN CAST(‘02049‘as nvarchar2(10))
ELSE CAST(‘2312‘ as nvarchar2(10)) END AS CLASSESCODE,
详细问题:https://blog.csdn.net/liuxiyangyang/article/details/8446692
以上是关于Oracle数据库中,使用case语句,遇到VARCHAR2与NVARCHAR2问题的主要内容,如果未能解决你的问题,请参考以下文章
SQL Server 2012:如何在 @Var 前后使用文字在 Case 语句中显示 @Var 结果
LIKE 在 CASE 语句中 Oracle SQL (Sql Developer)