'nvarche2'에 해당되는 글 1건

  1. 2014.05.20 oracle 타입 - nvarchar2 varchar2
프로그램 사용/oracle2014. 5. 20. 23:32
오라클에는 varchar2 라는 타입을 주로 사용하지만
이녀석은 char[] 로 1바이트 문자열을 최대 4000 byte까지 저장할 수 있다.
물론 4000 바이트라는건 최대 선언 가능한 길이일뿐
varcahr2 타입으로 선언한다고 해서 가변으로 0~4000자를 입력할수 있는건 아니다.
(이렇게 자동으로 길이 해주면 얼마나 좋았을까 -_-)

아무튼 요즘은 바야흐로(?) 유니코드 시대이기에 문자열 역시 유니코드로 저장하게 되는데
DB에서도 varchar2와 같이 1byte 문자열이 아닌 2byte 문자열(UTF-8 / UTF-16)을 지원해야 하고
이녀석은 nvarchar2로 N이 하나 더 붙게 된다.

VARCHAR2 and VARCHAR Datatypes

The VARCHAR2 datatype stores variable-length character strings. When you create a table with a VARCHAR2 column, you specify a maximum string length (in bytes or characters) between 1 and 4000 bytes for the VARCHAR2 column. For each row, Oracle stores each value in the column as a variable-length field unless a value exceeds the column's maximum length, in which case Oracle returns an error. Using VARCHAR2 and VARCHAR saves on space used by the table.

For example, assume you declare a column VARCHAR2 with a maximum size of 50 characters. In a single-byte character set, if only 10 characters are given for the VARCHAR2 column value in a particular row, the column in the row's row piece stores only the 10 characters (10 bytes), not 50.

Oracle compares VARCHAR2 values using nonpadded comparison semantics.

NCHAR and NVARCHAR2 Datatypes

NCHAR and NVARCHAR2 are Unicode datatypes that store Unicode character data. The character set of NCHAR and NVARCHAR2 datatypes can only be either AL16UTF16 or UTF8 and is specified at database creation time as the national character set. AL16UTF16 and UTF8 are both Unicode encoding.

The NCHAR datatype stores fixed-length character strings that correspond to the national character set.

The NVARCHAR2 datatype stores variable length character strings.

When you create a table with an NCHAR or NVARCHAR2 column, the maximum size specified is always in character length semantics. Character length semantics is the default and only length semantics for NCHAR or NVARCHAR2.

For example, if national character set is UTF8, then the following statement defines the maximum byte length of 90 bytes:

CREATE TABLE tab1 (col1 NCHAR(30));

This statement creates a column with maximum character length of 30. The maximum byte length is the multiple of the maximum character length and the maximum number of bytes in each character. 
[링크 : http://docs.oracle.com/cd/B19306_01/server.102/b14220/datatype.htm

If you prefer to implement Unicode support incrementally, or if you need to support multilingual data only in certain columns, then you can store Unicode data in either the UTF-16 or UTF-8 encoding form in SQL NCHAR datatypes (NCHAR, NVARCHAR2, and NCLOB). The SQL NCHAR datatypes are called Unicode datatypes because they are used only for storing Unicode data.

[링크 : http://docs.oracle.com/cd/B28359_01/server.111/b28298/ch6unicode.htm]

'프로그램 사용 > oracle' 카테고리의 다른 글

sql distinct  (0) 2014.05.29
oracle 대소문자 구분없이 검색하기  (0) 2014.05.28
oracle 타입 - nvarchar2 varchar2  (0) 2014.05.20
oracle view  (0) 2014.05.20
oracle alter  (0) 2014.05.20
oracle sequence 명령어  (0) 2014.05.11
Posted by 구차니

댓글을 달아 주세요