DB

[SQL] char vs varchar vs varchar2

728x90
반응형

char

The char data type is used to store the character values. It is a fixed-length data type i.e once initialized we cannot change the size at execution time. Hence, it is also called a Static datatype.

char는 고정된 길이만큼 사용하는 정적 데이터 타입

 

varchar

 The VarChar data type is used to store the character values. It is a variable-length data type i.e we can change the size of the character at the time of the execution. Hence, it is also called a Dynamic datatype.
 VARCHAR is an ANSI Standard that is used to distinguish between Null and Empty Strings. However, in Oracle VARCHAR and VARCHAR2 is totally the same.
 It is recommended to not use VARCHAR as Oracle may change its usage in the near future.

 

varchar2

VARCHAR2 is the same as VARCHAR in the oracle database. The main difference is that VARCHAR is ANSI Standard and VARCHAR2 is Oracle standard.

 

 varchar와 varchar2는 가변 길이 만큼 사용하는 동적 데이터 타입이고, varchar와 varchar2는 사실상 동일한 타입이다. varchar의 경우 ANSI 표준, varchar2는 Oracle 표준이라는 차이점이 존재한다.

 

 정적 데이터 타입은 null 데이터에도 고정된 공간을 할당한다. 동적 데이터 타입은 데이터의 크기에 맞춰 저장 공간을 줄여주기 때문에 규모가 커질수록(사실 상관없이) char 대신 varchar, varchar2를 사용하는것이 저장공간 절약 및 비용절감 면에서 유용하다.

 

 Oracle에서 varchar 대신 varchar2를 사용하는 것은 Oracle 사에서 현재의 varchar를 다른 용도로 변경할 예정이라 발표했기 때문이라 한다.