Search code examples
javaoracleutf-8eclipselink

Insert non-English string into UTF-8 Oracle database


I have a Oracle and it's encoding is UTF-8. When I insert some non-English string into it, I'll get ORA-12899. I think the reason is some non-English needs 3 bytes in UTF-8 system.

The simplest solution is to extend the length of Oracle. I want to trim the string and I can't find a single solution to trim the string. Are there any suggestions? I tried to get the byte length but the value is not for UTF-8.


Solution

  • Use lengthb() to get length in bytes. Truncate your string until it fits into column:

    while lengthb(x) > column_length_in_bytes loop
      x := substr(x, 1, length(x)-1);
    end loop;