以下代码为您提供了如何使用 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;