0

I am using N function to update NClob in SQL Query. However, the update using N function is not allowing me to update more than 1900 characters. After removing N function. I am able to update the more than 1900 characters to my NClob column.

Can anyone help me as to why I am not able to update the NClob column using N function? Is there any restriction on it?

Code is

StringBuilder updateQuery = new StringBuilder("update table_name set column_name ="); updateQuery.append(" = N'").append(NClobContent).append("'").append(" , "); ps.execute(updateQuery.toString());

user1661892
  • 103
  • 4
  • 13

1 Answers1

0

As stated in the documentation:

  • A text literal can have a maximum length of 4000 bytes.

The N means the literal is using the national character set, which will be either UTF8 or AL16UTF16 (the latter by default), so even if your long string has fewer then 4000 characters, it can still have more then 4000 bytes.

Without the N the string is interpreted in the database character set, and the literal is then converted to the nation character set as it is stored in your NCLOB. You can therefore potentially have a longer string - if your database character set is single-byte then you could ave up to 4000 characters, though any multibyte characters in your NClobCOntent variable would be corrupted.

Rather than using the N syntax, pass your variable to the database as a stream; you might find this answer a useful starting point. Or you might be able to use this approach, depending on the string length.

Community
  • 1
  • 1
Alex Poole
  • 183,384
  • 11
  • 179
  • 318
  • When I am using cstmt.setCharacterStream(), the backend function (which is receiving a NCLOB), is not able to hold the unicode characters. The whole purpose of doing all these is to store unicode characters (like Japanese or Russian characters) in NCLOB and using stream, I am not able to pass it to backend. – user1661892 Jan 13 '15 at 03:49