본문 바로가기

나 어제 배웠다/Database

DB2 Byte 문자열 자르기(한글)

select SUBSTR(REPLACE('년간1회금액입력,견적서금액상이,2회금액시2순위업체',' ',''),1,10)||'...'
     , SUBSTRING('년간1회금액입력,견적서금액상이,2회금액시2순위업체',1,10,CODEUNITS32)||'...'
     , SUBSTRING('년간1회금액입력,견적서금액상이,2회금액시2순위업체',1,10,CODEUNITS16)||'...'
     , SUBSTRING('년간1회금액입력,견적서금액상이,2회금액시2순위업체',1,10,OCTETS)||'...'
     , SUBSTRING('년간1회금액입력,견적서금액상이,2회금액시2순위업체',1,2,OCTETS)
  from SYSIBM.SYSDUMMY1;

 

Options to specify unit of measurement:

CODEUNITS16
Specifies that DB2 is to count the length by 16-bit (or 2-byte) code units. For every character that is 2 bytes or less in the string, DB2 counts a length of 1.
CODEUNITS32
Specifies that DB2 is to count the length by 32-bit (or 4-byte) code units. For every character that is 4 bytes or less in the string, DB2 counts a length of 1. CODEUNITS32 always returns the same value as CODEUNITS16 unless you have supplementary characters.
OCTETS
Specifies that DB2 is to count the length by bytes. For every byte in the string, DB2 counts a length of 1.

The OCTETS option is not available for all of the listed functions.

 

참고 URL

http://pic.dhe.ibm.com/infocenter/dzichelp/v2r2/index.jsp?topic=%2Fcom.ibm.db2z9.doc.char%2Fsrc%2Ftpc%2Fdb2z_specifylengthcalcutation.htm

'나 어제 배웠다 > Database' 카테고리의 다른 글

DB2 날짜 변환 참고  (0) 2013.08.26
DB2 MERGE 사용하기  (0) 2013.07.17
Random Select...  (0) 2012.06.15
with 구문 샘플  (0) 2010.12.15
MS SQL Server 날짜계산  (0) 2010.09.02