The character set type in Oracle determines the varchar2 character length.

Source: Internet
Author: User
1. When data is inserted into the database table a few days ago, the following error is reported: SQLgt; insertintostudentvalues (

1. When data is inserted into the database table a few days ago, the following error is reported: SQLgt; insert into student values (

1. the following error is reported when data is inserted into the database table a few days ago:

SQL> insert into student values ('People 'S REPUBLIC OF CHINA ', 60 );
Insert into student values ('People 'S republic of china ', 60)
*
Row 3 has an error:
ORA-12899: the value of column "SYSTEM". "STUDENT". "NAME" is too large (actual value: 12, maximum value: 6)

The character length is set to 6 when a table is created, but an error is reported when six Chinese characters are inserted. The table structure is as follows:

SQL> desc student;
Is the name empty? Type
-----------------------------------------------------------------------------
NAME VARCHAR2 (6)
Age number (3)

After checking a large amount of data, we found that the varchar2 length is determined by the character set type.

The content is as follows:

Varchar2 is up to 4000 bytes, So it depends on your Oracle character set. If the character set is 16-bit encoded, ZHS16GBK, that

Each character is 16 characters and 2 bytes. It can contain one Chinese character, so it can contain 2000 characters. If it is an AL32UTF8 character set, the three bytes are a Chinese character, then only 1333 characters can be stored.

2. view the statements of the character set type:

SQL> set wrap off;
SQL> select parameter, value from nls_database_parameters where parameter like 'nls _ CHARACTERSET ';

PARAMETER VALUE
-------------------------------------------------------------------------------
NLS_CHARACTERSET ZHS16GBK

Therefore, the characters inserted above can only be 3 Chinese characters.

If you change the character encoding above to 32-bit encoding, you can only store 1.5 Chinese characters.


3.10 view Character Set settings of the new database

SQL> set wrap off
SQL> set lines 1000
SQL> select * from nls_database_parameters;

4. You can use update props $ set value $ = 'zhs16gbk' where;
To modify character sets

5. If the character set is AL32UTF8, the following example shows that each Chinese Character occupies three bytes.

SQL> select lengthb ('中') from dual;

LENGTHB ('zhong ')
-------------
3

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.