Differences between varchar2 (20) and varchar2 (20 bytes) in Oracle

Source: Internet
Author: User

Development Environment: some table field types are defined as varchar2 (20) some table field types are defined as varchar2 (20 byte)

Is varchar2 (20) the same as varchar2 (20 byte?

The difference is determined by the database parameter nls_length_semantics, which has two units: Char (character) or byte. The default value of this parameter is byte.

Therefore, by default, varchar2 (20) = varchar2 (20 bytes ). If the parameter value is Char, It is not equal.

Suggestion: Use a unified format such as varchar2 (20)

Demo:

SQL> show parameter nls_length_semantics;

 

Name type value

-----------------------------------------------------------------------------

Nls_length_semantics string byte

SQL> Create Table tab1 (

2 ID number (10 ),

3 Description varchar2 (20)

4 );

 

Table created.

 

SQL> Create Table tab2 (

2 ID number (10 ),

3 Description varchar2 (20 char)

4 );

 

Table created.

 

SQL> DESC tab1;

Name null? Type

-----------------------------------------------------------------------------

ID number (10)

Description varchar2 (20)

 

SQL> DESC tab2;

Name null? Type

-----------------------------------------------------------------------------

ID number (10)

Description varchar2 (20 char)

SQL> alter session set nls_length_semantics = char;

 

Session altered.

 

SQL> Create Table tab3 (

2 ID number (10 ),

3 Description varchar2 (20)

4 );

 

Table created.

 

SQL> DESC tab1;

Name null? Type

-----------------------------------------------------------------------------

ID number (10)

Description varchar2 (20 byte)

 

SQL> DESC tab2;

Name null? Type

-----------------------------------------------------------------------------

ID number (10)

Description varchar2 (20)

 

SQL> DESC tab3;

Name null? Type

-----------------------------------------------------------------------------

ID number (10)

Description varchar2 (20)

Note: SYS and system are not affected by the nls_length_semantics and are always byte
Do not arbitrarily modify the system-level nls_length_semantics. Otherwise, some finished suites such as EBS may fail to run normally.

Related Article

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.