상위 필드에서 서브필드 선택

디리미트 서브필드가 포함 중인 메시지를 처리하는 메시지 플로우가 있을 수 있습니다. 서브필드의 디리미터를 알고 있는 경우 ESQL을 코드화하여 주변 컨텐츠에서 서브필드를 추출할 수 있습니다.

이 작업을 수행하는 기능 또는 유사 기능을 작성하는 경우 ESQL 모듈(Compute, Database 및 Filter 노드) 및 맵핑 파일(DataDelete, DataInsert, DataUpdate, Extract, Mapping 및 Warehouse 노드에 사용) 모두에서 호출할 수 있습니다.

다음 기능의 예에서는 특정 문자로 디리미트된 메시지의 특정 서브필드를 추출합니다.

CREATE FUNCTION SelectSubField (SourceString CHAR, Delimiter CHAR, TargetStringPosition INT) 
       RETURNS CHAR
-- This function returns a substring at parameter position TargetStringPosition within the      
-- passed parameter SourceString.  An example of use might be:
-- SelectSubField(MySourceField,' ',2) which will select the second subfield from the
-- field MySourceField delimited by a blank.  If MySourceField has the value
-- "First Second Third" the function will return the value "Second"
    BEGIN
    DECLARE DelimiterPosition INT;
    DECLARE CurrentFieldPosition INT 1;
    DECLARE StartNewString INT 1;
    DECLARE WorkingSource CHAR SourceString;
    SET DelimiterPosition = POSITION(Delimiter IN SourceString);
    WHILE CurrentFieldPosition < TargetStringPosition
     	DO
     		IF DelimiterPosition = 0  THEN
   			-- DelimiterPosition will be 0 if the delimiter is not found 
         -- exit the loop
     			SET CurrentFieldPosition = TargetStringPosition;
     		ELSE
     			SET StartNewString = DelimiterPosition + 1;
     			SET WorkingSource = SUBSTRING(WorkingSource FROM StartNewString);
     			SET DelimiterPosition = POSITION(Delimiter IN WorkingSource);
     			SET CurrentFieldPosition = CurrentFieldPosition + 1;
     		END IF;
    END WHILE;
    IF DelimiterPosition > 0 THEN
       -- Remove anything following the delimiter from the string
       SET WorkingSource = SUBSTRING(WorkingSource FROM 1 FOR DelimiterPosition);     	
       SET WorkingSource = TRIM(TRAILING Delimiter FROM WorkingSource);
    END  IF;  
    RETURN WorkingSource;
END;	
관련 개념
메시지 플로우 개요
관련 태스크
메시지 플로우 설계
메시지 플로우 컨텐츠 정의
관련 참조
Compute 노드
Database 노드
Filter 노드
ESQL 참조
DECLARE문
POSITION 함수
SET문
SUBSTRING 함수
TRIM 함수
WHILE문
주의사항 | 등록상표 | 다운로드 | 라이브러리 | 지원 | 피드백
Copyright IBM Corporation 1999, 2006 마지막 갱신 날짜: 2006/08/21
ac20400_