-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Oracle exception "ORA-12704: character set mismatch" if hash validation includes NVARCHAR columns #1406
Comments
Research We could use a special token in We would then override the Oracle
We would also need the raw Oracle data type in |
Hi, I could be making this more complicated, here is my research. Oracle has two encodings - NLS_CHARACTERSET for the VARCHAR data type and NLS_NCHAR_CHARACTERSET for the NVARCHAR2 data type. NLS_CHARACTERSET could have many different values - the default is One approach to address this is to convert all ORACLE strings to NVARCHAR2(2000), do all the manipulations we need, convert it to UTF8 and do the standard_hash as before. You can cast as Hope this helps Sundar Mudupalli |
Interesting discovery regarding convert(). That was introduced in commit 2e24eae. This is the issue that added it: #875 Even the part in the Oracle doc regarding RAW conversions is recommending it's use for characters in "neither the database nor the national character set". In relation to this issue, are you think if we always convert to the national character set then we don't need the code to get the raw data types? I believe I would still need the code to force the replacement literal to an nchar string. I feel the risk level has increased with the suggested change. We've gone from ensuring we provide a valid replacement literal to refining character set processing in addition to fixing the replacement literal. This is a lower priority issue for the customer that raised it so we have time to discuss this more deeply and give it more thought. |
During a row validation using the --hash "*" option we observed, that the SQL that is sent to Oracle behind the scenes produces an exception if the table being validated contains NVARCHAR columns.
The reason seems to be that the coalesce function used in the SQL generated by DVT that is called to replace null values with a non-empty String like 'DEFAULT_REPLACEMENT_STRING' requires two parameters of the same datatype . In case of a NVARCHAR column one parameter of the coalesce function is of type NVARCHAR using the configured NCHAR character set for that database and the second parameter (the replacement String) is of type CHAR using the default database charset which may be different from the NCHAR character set.
Example code to reproduce this exception:
CREATE TABLE nchartest (id NUMBER(5) PRIMARY KEY, content nvarchar2(10));
INSERT INTO nchartest VALUES (1, 'one');
INSERT INTO nchartest VALUES (2, 'two');
INSERT INTO nchartest VALUES (3, null);
SELECT id, coalesce(content, 'DEFAULT_REPLACEMENT_STRING') FROM nchartest;
The SELECT statement causes the observed character-set-mismatch exception. The exception disappears, if either the value of the content column is converted to the default database charset using to_char or the replacement String is marked as NCHAR value with a leading 'N'. So both of the following statements seem to work.
SELECT id, coalesce(to_char(content), 'DEFAULT_REPLACEMENT_STRING') FROM nchartest;
or
SELECT id, coalesce(content, N'DEFAULT_REPLACEMENT_STRING') FROM nchartest;
Can one of these solutions be applied to the SQL that is generated by DVT whenever COALESCE will get called on such nvarchar columns ? Is there any other solution or workaround to make concat or hash validations work with NCHAR columns ?
The text was updated successfully, but these errors were encountered: