ORA-12704:字符集不匹配

在使用union all连接时,若A集合中某列为nvarchar2或nvarchar2类型,而B集合中无此列,用
''来代替或者说B集合中此列为varchar2类型,会报字符集不匹配的错误,

如下:

sys@ORCL> select cast('测试' as nvarchar2(10)) t from dual
  2  union all
  3  select '' from dual;
select cast('测试' as nvarchar2(10)) t from dual
       *
ERROR at line 1:
ORA-12704: character set mismatch

解决方法

1.to_char()

sys@ORCL> select to_char(cast('测试' as nvarchar2(10))) t from dual
  2  union all
  3  select '' from dual;

2.用N',N''就是讲''转换为unicode编码

sys@ORCL> select '中国','China',cast('中国' as nvarchar2(10)) T from dual 
union all select '美国','USA',N'' from dual;
评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符 “速评一下”
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页