1. 程式人生 > >ORA-12704:字符集不匹配

ORA-12704:字符集不匹配

在使用union all連線時,若A集合中某列為nvarchar2或nvarchar2型別,而B集合中無此列,用
''來代替或者說B集合中此列為varchar2型別,會報字符集不匹配的錯誤,

如下:

[email protected]> 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()

[email protected]> select to_char(cast('測試' as nvarchar2(10))) t from dual
  2  union all
  3  select '' from dual;

2.用N',N''就是講''轉換為unicode編碼

[email protected]> select '中國','China',cast('中國' as nvarchar2(10)) T from dual  union all select '美國','USA',N'' from dual;