How many bytes do Chinese characters occupy in Oracle?

        Do you often encounter that a certain field in the data table is not long enough? Generally, we use the VARCAHR2 type when storing strings, and VARCHAR2 has two uses, one is VARCHAR2 (10 btye), and the other is VARCHAR2 (10 char). The former is the default value, which means 10 bytes, and the latter means 10 characters.

       How many bytes a Chinese character occupies is related to the character set of the Oracle library. If the character set is ZHS16GBK, one Chinese character occupies 2 bytes; if the character set is AL32UTF8, one Chinese character occupies 3 bytes .

        If you look at Oracle's character set:

        

SELECT * FROM v$nls_parameters WHERE PARAMETER='NLS_CHARACTERSET';

        If you don’t want to check the character set of the current database and want to know how many bytes a Chinese character occupies in the current Oracle library, you can use the lengthb() function. This is to check how many bytes a Chinese character occupies in the current database .

        The length() function checks how many characters the current string occupies, which is the length of the string.

select  lengthb('中国')  from dual; // 6个字节

Guess you like

Origin blog.csdn.net/dhklsl/article/details/132831439