본문 바로가기

[오라클 레퍼런스 함수] TO_CHAR (character) - 문자 데이터를 데이터베이스 문자 집합(database character set)으로 변환

by ㅇㅍㅍ 2023. 8. 29.
[오라클 레퍼런스 함수] TO_CHAR (character) - 문자 데이터를 데이터베이스 문자 집합(database character set)으로 변환
728x90

 

TO_CHAR (character)

 

구문

TO_CHAR(nchar | clob | nclob)

 

목적

TO_CHAR (character) 함수는 NCHAR, NVARCHAR2, CLOB 또는 NCLOB 데이터를 데이터베이스 문자 집합(database character set)으로 변환합니다. 반환되는 값은 항상 VARCHAR2입니다.

이 함수를 사용하여 문자 LOB을 데이터베이스 문자 집합으로 변환할 때 변환할 LOB 값이 대상 형식보다 큰 경우 데이터베이스에서 오류가 발생합니다.

 

참고:

Oracle Database Globalization Support Guide의 부록 C는이 함수의 문자 리턴 값에 할당되는 콜레이션을 정의하는 정렬 파생 규칙(collation derivation rules)에 대한 정보를 제공합니다.

 

예제

다음 예제에서는 간단한 문자열을 문자 데이터로 해석합니다.

SELECT TO_CHAR('01110') FROM DUAL;

TO_CH
-----
01110

 

이 예제는 TO_CHAR (number)의 첫 번째 예제와 비교하십시오.
다음 예제는 pm.print_media 테이블에서 일부 CLOB 데이터를 데이터베이스 문자 집합으로 변환합니다.

SELECT TO_CHAR(ad_sourcetext) FROM print_media
      WHERE product_id = 2268;

TO_CHAR(AD_SOURCETEXT)
--------------------------------------------------------------------
******************************
TIGER2 2268...Standard Hayes Compatible Modem
Product ID: 2268
The #1 selling modem in the universe! Tiger2's modem includes call management
and Internet voicing. Make real-time full duplex phone calls at the same time
you're online.
**********************************

 

TO_CHAR (character) 함수: 예제

다음 문은 empl_temp라는 테이블을 생성하고 직원 세부 정보로 채웁니다:

CREATE TABLE empl_temp 
  ( 
     employee_id NUMBER(6), 
     first_name  VARCHAR2(20), 
     last_name   VARCHAR2(25), 
     email       VARCHAR2(25), 
     hire_date   DATE DEFAULT SYSDATE, 
     job_id      VARCHAR2(10), 
     clob_column CLOB 
  );

INSERT INTO empl_temp
VALUES(111,'John','Doe','example.com','10-JAN-2015','1001','Experienced Employee');

INSERT INTO empl_temp
VALUES(112,'John','Smith','example.com','12-JAN-2015','1002','Junior Employee');

INSERT INTO empl_temp
VALUES(113,'Johnnie','Smith','example.com','12-JAN-2014','1002','Mid-Career Employee');

INSERT INTO empl_temp
VALUES(115,'Jane','Doe','example.com','15-JAN-2015','1005','Executive Employee');

 

다음 문은 CLOB 데이터를 데이터베이스 문자 집합으로 변환합니다:

SELECT To_char(clob_column) "CLOB_TO_CHAR" 
FROM   empl_temp 
WHERE  employee_id IN ( 111, 112, 115 );

CLOB_TO_CHAR
--------------------
Experienced Employee
Junior Employee
Executive Employee

 

Live SQL: Oracle Live SQL에서 Using the TO_CHAR Function 예제를 보고 실행하세요.

 


출처: 오라클 레퍼런스

원문 링크: Oracle TO_CHAR (character) 함수 문서

 

반응형

댓글