오경석의 개발노트

Oracle_Data Type 본문

프로그래밍 언어/Oracle

Oracle_Data Type

OHSAYU 2023. 11. 5. 11:25
Data Type Description
VARCHAR2(size [BYTE | CHAR]) Variable-length character string having maximum length size bytes or characters.
You must specify size for VARCHAR2. Minimum size is 1 byte or 1 character.
Maximum size is:

32767 bytes or characters if MAX_STRING_SIZE = EXTENDED

4000 bytes or characters if MAX_STRING_SIZE = STANDARD

Refer to Extended Data Types for more information on the MAX_STRING_SIZE 
initialization parameter.

BYTE indicates that the column will have byte length semantics. 
CHAR indicates that the column will have character semantics.
NVARCHAR2(size) Variable-length Unicode character string having maximum length size characters. 
You must specify size for NVARCHAR2. The number of bytes can be up to two times 
size for AL16UTF16 encoding and three times size for UTF8 encoding. Maximum size 
is determined by the national character set definition, with an upper limit of:

32767 bytes if MAX_STRING_SIZE = EXTENDED

4000 bytes if MAX_STRING_SIZE = STANDARD

Refer to Extended Data Types for more information on the 
MAX_STRING_SIZE initialization parameter.
NUMBER [ (p [, s]) ] Number having precision p and scale s. The precision p can range from 1 to 38. 
The scale s can range from -84 to 127. Both precision and scale are in decimal 
digits. A NUMBER value requires from 1 to 22 bytes.
FLOAT [(p)] A subtype of the NUMBER data type having precision p. A FLOAT value is represented 
internally as NUMBER. The precision p can range from 1 to 126 binary digits. 
A FLOAT value requires from 1 to 22 bytes.
LONG Character data of variable length up to 2 gigabytes, or 231 -1 bytes. Provided for 
backward compatibility.
DATE Valid date range from January 1, 4712 BC, to December 31, 9999 AD. The default 
format is determined explicitly by the NLS_DATE_FORMAT parameter or implicitly by 
the NLS_TERRITORY parameter. The size is fixed at 7 bytes. This data type contains 
the datetime fields YEAR, MONTH, DAY, HOUR, MINUTE, and SECOND. It does not 
have fractional seconds or a time zone.
BINARY_FLOAT 32-bit floating point number. This data type requires 4 bytes.
BINARY_DOUBLE 64-bit floating point number. This data type requires 8 bytes.
TIMESTAMP [(fractional_seconds_precision)] Year, month, and day values of date, as well as hour, minute, and second values of 
time, where fractional_seconds_precision is the number of digits in the fractional part 
of the SECOND datetime field. Accepted values of fractional_seconds_precision are 
0 to 9. The default is 6. The default format is determined explicitly by the 
NLS_TIMESTAMP_FORMAT parameter or implicitly by the NLS_TERRITORY 
parameter. The size is 7 or 11 bytes, depending on the precision. This data type 
contains the datetime fields YEAR, MONTH, DAY, HOUR, MINUTE, and SECOND. 
It contains fractional seconds but does not have a time zone.
TIMESTAMP [(fractional_seconds_precision)] WITH TIME ZONE All values of TIMESTAMP as well as time zone displacement value, where 
fractional_seconds_precision is the number of digits in the fractional part of the 
SECOND datetime field. Accepted values are 0 to 9. The default is 6. The default date 
format for the TIMESTAMP WITH TIME ZONE data type is determined by the 
NLS_TIMESTAMP_TZ_FORMAT initialization parameter. The size is fixed at 13 
bytes. This data type contains the datetime fields YEAR, MONTH, DAY, HOUR, 
MINUTE, SECOND, TIMEZONE_HOUR, and TIMEZONE_MINUTE. It has fractional 
seconds and an explicit time zone.
TIMESTAMP [(fractional_seconds_precision)] WITH LOCAL TIME ZONE All values of TIMESTAMP WITH TIME ZONE, with the following exceptions:
  • Data is normalized to the database time zone when it is stored in the database.
  • When the data is retrieved, users see the data in the session time zone.
The default format is determined explicitly by the NLS_TIMESTAMP_FORMAT 
parameter or implicitly by the NLS_TERRITORY parameter. The size is 7 or 11 bytes,
depending on the precision.
INTERVAL YEAR [(year_precision)] TO MONTH Stores a period of time in years and months, where year_precision is the number of 
digits in the YEAR datetime field. Accepted values are 0 to 9. The default is 2. The size 
is fixed at 5 bytes.
INTERVAL DAY [(day_precision)] TO SECOND [(fractional_seconds_precision)] Stores a period of time in days, hours, minutes, and seconds, where

day_precision is the maximum number of digits in the DAY datetime field. Accepted 
values are 0 to 9. The default is 2.

fractional_seconds_precision is the number of digits in the fractional part of the 
SECOND field. Accepted values are 0 to 9. The default is 6.

The size is fixed at 11 bytes.
RAW(size) Raw binary data of length size bytes. You must specify size for a RAW value. 
Maximum size is:

32767 bytes if MAX_STRING_SIZE = EXTENDED

2000 bytes if MAX_STRING_SIZE = STANDARD

Refer to Extended Data Types for more information on the MAX_STRING_SIZE 
initialization parameter.
LONG RAW Raw binary data of variable length up to 2 gigabytes.
ROWID Base 64 string representing the unique address of a row in its table. This data type is 
primarily for values returned by the ROWID pseudocolumn.
UROWID [(size)] Base 64 string representing the logical address of a row of an index-organized table. 
The optional size is the size of a column of type UROWID. The maximum size and 
default is 4000 bytes.
CHAR [(size [BYTE | CHAR])] Fixed-length character data of length size bytes or characters. Maximum size is 2000 
bytes or characters. Default and minimum size is 1 byte.

BYTE and CHAR have the same semantics as for VARCHAR2.
NCHAR[(size)] Fixed-length character data of length size characters. The number of bytes can be up 
to two times size for AL16UTF16 encoding and three times size for UTF8 encoding. 
Maximum size is determined by the national character set definition, with an upper 
limit of 2000 bytes. Default and minimum size is 1 character.
CLOB A character large object containing single-byte or multibyte characters. 
Both fixed-width and variable-width character sets are supported, both using the 
database character set. Maximum size is (4 gigabytes - 1) * (database block size).
NCLOB A character large object containing Unicode characters. Both fixed-width and 
variable-width character sets are supported, both using the database national 
character set. Maximum size is (4 gigabytes - 1) * (database block size). Stores 
national character set data.
BLOB A binary large object. Maximum size is (4 gigabytes - 1) * (database block size).
BFILE Contains a locator to a large binary file stored outside the database. Enables byte 
stream I/O access to external LOBs residing on the database server. Maximum size 
is 4 gigabytes.

 

 

 

1. 문자 데이터 타입

데이터 타입 설명
CHAR (크기[ BYTE | CHAR ]) 고정길이 문자, 최대 2000byte, 디폴트 값은 1byte
VARCARCHAR2 (크기[ BYTE | CHAR ]) 가변길이 문자, 최대 4000byte, 디폴트 값은 1byte
NCHAR (크기) 고정길이 유니코드 문자(다국어 입력 가능), 최대 2000byte, 
디폴트 값은 1
NVARCARCHAR2 (크기) 가변길이 유니코드 문자(다국어 입력 가능), 최대 4000byte, 
디폴트 값은 1
LONG 최대 2GB 크기의 가변길이 문자형, 
잘 사용하지 않음->CLOB / BLOB
  • 특정 컬럼을 VARCHAR2(10)으로 선언하면, 10byte까지 데이터를 입력할 수 있다. 'abc'라고 세 글자만 입력하면 실제 컬럼 길이는 3byte가 된다. 
  • 고정길이 CHAR(10)으로 만든 후 'abc'라고 입력하면 세 문자만 입력됐더라도 이 컬럼 길이는 10byte가 된다.
  • 영어에서 한 문자는 1byte, 한글은 2byte를 차지한다.

 

숫자 데이터 타입

데이터 타입 설명
NUMBER [(p, [s])] 가변숫자, p(1~38, 디폴트 값은 38)와 s(-84~127, 디폴트 값은 0)는 십진수 기준, 최대 22byte
FLOAT[(p)] NUMBER의 하위 타입, p는 1~128, 디폴트 값은 128, 
이진수 기준, 최대 22byte
BINARY_FLOAT 32비트 부동소수점 수, 최대 4byte
BINARY_DOUBLE 64비트 부동소수점 수, 최대 8byte
  • 오라클에도 다른 숫자 타입이 있지만 내부적으로는 모두 NUMBER형으로 변환되어 생성된다.

 

날짜 데이터 타입

데이터 타입 설명
DATE BC 4712년 1월 1일부터 9999년 12월 31일, 연,월,일,시,분,초까지 입력 가능하다.
TIMESTAMP[(fractional_seconds_precision)] 연도, 월, 일, 시, 분, 초는 물론 밀리초까지 입력 가능하다.
fractional_seconds_precision은 0~9까지 입력할 수 있고 디폴트 값은 6이다.

 

 

LOB 데이터 타입

데이터 타입 설명
CLOB 문자형 대용량 객체. 고정길이와 가변길이 문자 집합 지원, 
최대 크기는 (4GB-1) * (데이터베이스 블록 사이즈)
NCLOB 유니코드(다국어 지원)를 포함한 문자형 대용량 객체. 
최대 크기는 (4GB-1) * (데이터베이스 블록 사이즈)
BLOB 이진형 대용량 객체. 최대 크기는(4GB-1) * (데이터베이스 
블록 사이즈)
BFILE 대용량 이진 파일에 대한로케이터(위치, 이름)저장. 
최대 크기는 4GB

 

 

출처 : https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/Data-Types.html#GUID-1BABC478-FB47-4962-9B0C-8B8BD059E733

 

SQL Language Reference

 

docs.oracle.com

출처 : https://prinha.tistory.com/entry/Oracle-DataType-%EC%98%A4%EB%9D%BC%ED%81%B4-%EB%8D%B0%EC%9D%B4%ED%84%B0-%ED%83%80%EC%9E%85%EC%9D%98-%EC%A2%85%EB%A5%98

 

[Oracle] DataType / 오라클 데이터 타입의 종류

데이터 타입(DataType)이란 컬럼이 저장되는 데이터 유형을 말하며, 오라클에서는 기본적으로 제공되는 기본 데이터 타입(원시 데이터 타입)과 사용자 정의 데이터 타입으로 구분할 수 있다. 사용

prinha.tistory.com

 

Comments