---
title: "关于Union 中 ORA-12704:字符集不匹配问题的解决"
author: "slbszq"
date: "2015-05-05T11:30:14Z"
tags: []
categories: ["数据库"]
slug: "union-ora-12704"
draft: false
lastmod: "2015-05-05T11:30:14Z"
id: 2208520
url: "https://it4j.iteye.com/blog/2208520"
---

**在使用Union all连接时，若A集合中某列为nvarchar2或nvarchar类型，而B集合中无此列，用‘ ’ 来代替是会报字符集不匹配**，解决方法有两种，见下面的示例：

```
select '中国','China',cast('中国' as nvarchar2(10)) T
from dual
union all
select '美国','USA','' 
from dual;
```

 如上，T的类型为nvarchar2，长度为10，如果直接这样查询，就会报字符集不匹配，那么怎么来处理呢，可通过两种方法来解决

 

**1.to\_char()**

```
select '中国','China',to_char(cast('中国' as nvarchar2(10))) T
from dual
union all
select '美国','USA','' 
from dual;
```

 **2. 用N' ',N''是将‘’转换为Unicode编码**

```
select '中国','China',cast('中国' as nvarchar2(10)) T
from dual
union all
select '美国','USA',N'' 
from dual;
```

 这样就可以解决字符集不匹配问题了

引用: [http://blog.csdn.net/lqh4188/article/details/7498354](http://blog.csdn.net/lqh4188/article/details/7498354)