Wednesday, April 9, 2014

ORA-12704: character set mismatch

I have replicate the above error using below query :

Select case when job = 'CLERK' then 'C' else replace(upper(ename),' ' ,'') end || '_'||job  as job_type from emp;

Above query is working fine with "emp" table, if column ENAME , JOB having "VARCHAR" datatype.
It will throw error if changed it to NVARCHAR.

For this we need to modified the "emp" table:
alter table emp modify ename nvarchar2(10);
alter table emp modify job nvarchar2(10);



Select case when job = 'CLERK' then 'C' else replace(upper(ename),' ' ,'') end || '_'||job  as job_type from emp;
ORA-12704: character set mismatch


Solution: USE N FUNCTION (the N function converts the data to nvarchar at compilation time)
Select case when job = 'CLERK' then N'C' else replace(upper(ename),' ' ,'') end || '_'||job  as job_type from emp;


Casue:
source(ora-12704.ora-code.com)
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.

1 comment:

web stats