2012-05-01 1 views
0

내 사용자는 일반 텍스트 전자 메일 메시지를 잘라내어 Application Express에 붙여 넣을 수 있으며 전자 메일 내용을 구문 분석하여 표. 전자 메일 메시지는 일반적으로 10,000 - 20,000 자이므로 전자 메일을 VARCHAR2 또는 CLOB에 넣을 수 있습니다.PL/SQL을 사용하여 구조화 된 일반 텍스트 전자 메일 메시지를 구문 분석하는 방법 찾기

나는 VARCHAR2 또는 CLOB를 채운 후에 이러한 이메일을 구문 분석하는 방법에 대해 guidiance/pseudocode/hints를 요청합니다. 그래서

Item One: content for item one 

Item Two: 

multiline content for item two 
more multiline content for item two 

********************************* <- these asterisks are in the text 
Section Header I don't care about 
********************************* 

Item Three: content for item three 

과 :

메시지는 다음과 같은 형식을 가지고있다.

항목 머리글은 미리 알려져 있으며 일정하고 정의 된 순서입니다.

이것은 Oracle에서 호스팅되는 Apex 인스턴스에서 구현되므로 PL/SQL을 통해 수행하는 것을 선호하지만 PL/SQL이 많이 사용되는 자바도 사용할 수 있다고 생각합니다.

+1

가장 먼저 시도 할 것은 정규 표현식입니다. 오라클의 정규 표현식 지원에 대해 읽어보고. 행운을 빕니다. –

답변

1

다음 코드는 instr 및 substr을 사용하는 방법에 대한 예제입니다. 이 코드를 루프에 넣고 l_header_first 및 l_header_next를 채워 원하는 모든 값을 얻을 수있는 방법은 추가로 필요합니다.

declare 
    l_email  varchar2(32767); 
    l_first  pls_integer; 
    l_next   pls_integer; 
    l_text   varchar2(32767); 
    l_header_first varchar2(100); 
    l_header_next varchar2(100); 

begin 
    l_email := 'Item One: content for item one 

Item Two: 

multiline content for item two 
more multiline content for item two 

********************************* <- these asterisks are in the text 
Section Header I don''t care about 
********************************* 

Item Three: content for item three'; 

    l_header_first := 'Item One:'; 
    l_header_next := 'Item Two:'; 
    l_first  := instr(l_email, l_header_first) + length(l_header_first) + 1; 
    l_next   := instr(l_email, l_header_next); 

    l_text := substr(l_email, l_first, l_next - l_first); 
    dbms_output.put_line('Found ' || l_header_first); 
    dbms_output.put_line(l_text); 

    l_header_first := 'Item Two:'; 
    l_header_next := 'Item Three:'; 
    l_first  := instr(l_email, l_header_first) + length(l_header_first) + 1; 
    l_next   := instr(l_email, l_header_next); 

    l_text := substr(l_email, l_first, l_next - l_first); 
    dbms_output.put_line('Found ' || l_header_first); 
    dbms_output.put_line(l_text); 

end; 
+0

의견과 답변 사이에 도움을 주셔서 감사합니다. 모두 설정되었습니다. – cjs

관련 문제