In Oracle, the field type is often set to varchar2.
In the past, we thought that each Chinese Character occupies 2 bytes, that is, varchar2 (30) can only store 15 Chinese or 30 English characters.
Today, I accidentally discovered that this is actually related to Oracle configuration and can be queried using the following statement:
Select * from V $ nls_parameters t where T. Parameter = 'nls _ characterset ';
You can query the character set of the current database. If value = gb2312, a Chinese character occupies 2 bytes. If value = al32utf8, a Chinese character occupies 3 bytes.
In Java, you can use the following method to obtain the length of a string:
Private int getlength (ncstextfield t ){
Try {
Int ilength = new string (T. gettext (). getbytes ("utf8"), "iso-8859-1"). Length ();
Return ilength;
} Catch (exception e ){
Return T. gettext (). Length ();
}
}
In this way, a Chinese character occupies three bytes,
If you change utf8 to gb2312, one Chinese Character occupies 2 bytes.