when using the union all connection, if a set of a column nvarchar2 or nvarchar type, and B in the collection does not have such columns, "to replace is the character set mismatch, there are two workarounds, see the following example
Cases:
- Select ' China ',' Chinese ',cast (' China ' as nvarchar2 ()) T
- From dual
- Union All
- Select ' USA ', 'USA ', '
- from dual;
Select ' China ', ' Chinese ', cast (' China ' as Nvarchar2 ') tfrom dualunion allselect ' us ', ' USA ', ' from dual;
As above, the type of T is nvarchar2, length is 10, if this query directly, will be reported character set mismatch, then how to deal with it, there are two ways to solve
1.to_char ()
- Select ' China ',' Chinese ', To_char (cast (' China ' as nvarchar2 ())) T
- From dual
- Union All
- Select ' USA ', 'USA ', '
- from dual;
Select ' China ', ' Chinese ', To_char (CAST (' China ' as Nvarchar2 ')) tfrom dualunion allselect ' us ', ' USA ', ' from dual;
2. Using n ', n ' is converting ' ' to Unicode encoding
- Select ' China ',' Chinese ',cast (' China ' as nvarchar2 ()) T
- From dual
- Union All
- Select ' USA ',' USA ', N'
- from dual;
Select ' China ', ' Chinese ', cast (' China ' as Nvarchar2 ') tfrom dualunion allselect ' us ', ' USA ', N ' from dual;
This will solve the character set mismatch problem.
Oracle Union ORA-12704: The resolution of the character set mismatch problem.