1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
mhouri.world > create or replace
2 package split_text
3 IS
4
5 TYPE t_msg_array IS TABLE OF VARCHAR2(4000) INDEX BY BINARY_INTEGER;
6
7
8 FUNCTION f_extract_message_info_regexp (piv_message IN VARCHAR2
9 ,piv_delim IN VARCHAR2)
10 RETURN t_msg_array;
11
12
13 END split_text;
14 /
Package created.
mhouri.world > create or replace
2 package body split_text
3 IS
4
5 FUNCTION f_extract_message_info_regexp (piv_message IN VARCHAR2
6 ,piv_delim IN VARCHAR2)
7 /* ***************************************************************
8 * Name : f_extract_message_info *
9 * Author : Mohamed Houri *
10 * Abstract : it extracts tables fields from a payload message *
11 *****************************************************************/
12 RETURN t_msg_array
13 IS
14 l_t_msg_array t_msg_array;
15 ln_pos NUMBER := 0;
16 li INTEGER := 0;
17 lv_str VARCHAR2 (4000) := piv_message;
18
19 BEGIN
20 -- get the first position of the string
21 ln_pos := INSTR (lv_str, piv_delim, 1, 1);
22
23 WHILE (ln_pos != 0)
24 LOOP
25 -- Increment the array string counter
26 li := li + 1;
27
28 -- Create array element
29 l_t_msg_array (li) := substr (regexp_substr (lv_str, '#@[^#@]*', 1, 1), 3);
30
31 -- Remove from the original message the part of info that has been extracted
32 lv_str := substr (lv_str, ln_pos + 1, length (lv_str));
33
34 -- Determine the new position of first delimiter in the string
35 ln_pos := instr (lv_str, piv_delim, 1, 1);
36
37 END LOOP;
38
39 RETURN l_t_msg_array;
40 END f_extract_message_info_regexp;
41
42 END split_text;
43 /
Package body created.
mhouri.world > declare
2 piv_txt varchar2(4000);
3 l_t_jus_msg_array split_text.t_msg_array;
4
5 BEGIN
6
7 piv_txt := '#@test01#@test02#@test03';
8
9 l_t_jus_msg_array := split_text.f_extract_message_info_regexp(piv_txt,'#@');
10
11 dbms_output.put_line(' item1 := '||l_t_jus_msg_array(1) );
12 dbms_output.put_line(' item2 := '||l_t_jus_msg_array(2));
13 dbms_output.put_line(' item3 := '||l_t_jus_msg_array(3));
14
15
16 END;
17 /
item1 := test01
item2 := test02
item3 := test03
PL/SQL procedure successfully completed. |
Partager