The ORACLE10G database table field in the project is a varchar (n) type, which is simple to keep in English, as long as the number of letters is not greater than N. But for Chinese characters, the same approach is not. Because of the different character sets for Chinese characters, the bytes consumed in the database are not the same. UTF-8 character Set, a Chinese character accounted for three bytes, GBK character set, a Chinese character accounted for two bytes, such as varchar (10) Type of field, UTF-8 Chinese characters, can only save 3, GBK character set can save 5 characters.
So in the program according to the size of the table field varchar, save or update to make the necessary checks or the background will be error.
Methods: 1, using the table maxlength attributes, such as maxlength= "5", that is, only 5 characters can be saved.
MySQL version above 5.0:
1. How much length of a Chinese character is related to coding:
UTF-8: One kanji = 3 bytes
GBK: one kanji = 2 bytes
2.varchar (n) represents n characters, both Chinese and English, MySQL can be stored in n characters, only the actual byte length is different
3.MySQL check length, available in SQL language:
Select LENGTH (fieldname) from TableName to view
A Chinese character occupies a few bytes in the database