Question: What
causes the ORA-12704 error? I am doing a SQL UNION ALL
query:
ORA-12704 character set mismatch
What is the fix for the ORA-12704 error?
Answer: The oerr utility shows
this for the ORA-12704 error:
ORA-12704 character set mismatch
Cause: One of the following:
-
The string operands (other
than an NLSPARAMS argument) to an operator or built-in
function do not have the same character set.
-
An NLSPARAMS operand is not in
the database character set.
-
String data with character set
other than the database character set is passed to a
built-in function not expecting it.
-
The second argument to CHR() or
CSCONVERT() is not CHAR_CS or NCHAR_CS.
-
A string expression in the VALUES
clause of an INSERT statement, or the SET clause of an
UPDATE statement, does not have the same character set
as the column into which the value would be inserted.
-
A value provided in a DEFAULT
clause when creating a table does not have the same
character set as declared for the column.
-
An argument to a PL/SQL function
does not conform to the character set requirements of
the corresponding parameter.
Action: Strings
declared with NCHAR or NCHAR VARYING do not interoperate
with strings declared with CHAR or VARCHAR2. Use TRANSLATE()
function to explicitly convert one to the other.
As we see, the ORA-12704 error can have many fixes and
solutions. This little demonstration shows the
ORA-12704 error:
SQL>
create table tbl1(x varchar2(10));
Table
created.
SQL>
create table tbl2(x nvarchar2(10));
Table
created.
SQL>
select * from tbl1 union all select * from tbl2;
select * from tbl1 union all
select * from tbl2
*
ERROR at line 1:
ORA-12704: character set mismatch
here we see how a CAST operator can fix an ORA-12704
error:
SQL> select
test from mytest union select '' from mytest;
select test from mytest union
select '' from mytest
*
ERROR at line 1:
ORA-12704: character set mismatch
SQL> select test from mytest union
select cast('' as nvarchar2(100)) from mytest;
TEST
Here wee see how a UNION all character set mismatch was
solved with a "translate" command:
select
a.product from my_product a
union all
select 'Overall' from my_product
b;
Aafter I translate the column 'Overall' into nchar_cs,
the problem is fixed,
select a.product from my_product a
union all
select translate ('Overall' using
nchar_cs) product from my_product b;
|
|
|
Oracle Training from Don Burleson
The best on site
"Oracle
training classes" are just a phone call away! You can get personalized Oracle training by Donald Burleson, right at your shop!
|
|
|
|
|
Burleson is the American Team
Note:
This Oracle
documentation was created as a support and Oracle training reference for use by our
DBA performance tuning consulting professionals.
Feel free to ask questions on our
Oracle forum.
Verify
experience!
Anyone
considering using the services of an Oracle support expert should
independently investigate their credentials and experience, and not rely on
advertisements and self-proclaimed expertise. All legitimate Oracle experts
publish
their Oracle
qualifications.
Errata?
Oracle technology is changing and we
strive to update our BC Oracle support information. If you find an error
or have a suggestion for improving our content, we would appreciate your
feedback. Just
e-mail:
and include the URL for the page.
Copyright © 1996 - 2020
All rights reserved by
Burleson
Oracle ®
is the registered trademark of Oracle Corporation.
|
|