Resolution of the ORA-12704: Character set mismatch problem in Oracle Union.

Source: Internet
Author: User

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:

    1. Select ' China ',' Chinese ',cast (' China ' as nvarchar2 ()) T
    2. From dual
    3. Union All
    4. Select ' USA ', 'USA ', '
    5. 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 ()

    1. Select ' China ',' Chinese ', To_char (cast (' China ' as nvarchar2 ())) T
    2. From dual
    3. Union All
    4. Select ' USA ', 'USA ', '
    5. 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

    1. Select ' China ',' Chinese ',cast (' China ' as nvarchar2 ()) T
    2. From dual
    3. Union All
    4. Select ' USA ',' USA ', N'
    5. 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.