dplinnane
asked on
using regexp_instr to find the number of occurences of a delimeter
SELECT
REGEXP_INSTR('500 Oracle Parkway, Redwood Shores, CA', '[^,]+', 1, 2) "REGEXP_INSTR"
FROM DUAL;
the above gets the position of the second comma
How would I modify the above to find the number of occurences of a comma. Not sure if this is the way to go. Any sugestions appreciated.
Thanks in advance.
REGEXP_INSTR(<source_strin g>, <pattern>, <start_position>, <occurrence>, <return_option>, <match_parameter>)
REGEXP_INSTR('500 Oracle Parkway, Redwood Shores, CA', '[^,]+', 1, 2) "REGEXP_INSTR"
FROM DUAL;
the above gets the position of the second comma
How would I modify the above to find the number of occurences of a comma. Not sure if this is the way to go. Any sugestions appreciated.
Thanks in advance.
REGEXP_INSTR(<source_strin
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Great thanks both will be useful for what I want. Will split points.
ASKER
This what I came up with slight modification to account for length of delimiter, divide by the length of delim. Probably faster then translate, my string will be up to 1.5mb
DECLARE
n_count varchar2(1000) :=0;
PIN_PRICE_EVENT_MSG CLOB;
pin_delim varchar2(10) := '||';
BEGIN
PIN_PRICE_EVENT_MSG := '<?xml version="1.0"?><PDATA><HDR >200607||| 03190133~R MS</HDR><E VH>31~0000 6~20474517 5~P~Y~N~20 060704|||0 00100~2006 0712235900 ~Prom 1 - Laks</EVH><EVD>204745175~0 4608||437~ 14.99~A~A< /EVD><EVH> 18~00006~2 04745175~P ~Y~N~20060 704000100~ 2006071223 5900~Prom 1 - Laks</EVH><EVD>18-20474517 5~04608455 ~8.99~A~A< /EVD><EVH> 32~00006~2 04745176~P ~Y~N~20060 704000100~ 2006071223 5900~Prm 2 - Laks</EVH><EVD>204745176~0 4622331~14 .49~A~S</E VD><EVH>31 ~00006~204 745176~P~Y ~N~2006070 4000100~20 0607122359 00~Prm 2 - Laks</EVH><EVD>204745176~0 4622439~13 .49~A~S</E VD><EVH>31 ~00010~204 745175~P~Y ~N~2006070 4000100~20 0607122359 00~Prom 1 - Laks</EVH><EVD>204745175~0 4608437~14 .99~A~A</E VD><EVH>31 ~00010~204 745175~P~Y ~N~2006070 4000100~20 0607122359 00~Prom 1 - Laks</EVH><EVD>204745175~0 4608455~8. 99~A~A</EV D><EVH>31~ 00010~2047 45176~P~Y~ N~20060704 000100~200 6071223590 0~Prm 2 - Laks</EVH><EVD>204745176~0 4622331~14 .49~A~S</E VD><EVH>31 ~00010~204 745176~P~Y ~N~2006070 4000100~20 0607122359 00~Prm 2 - Laks</EVH><EVD>204745176~0 4622439~13 .49~A~S</E VD></PDATA >';
select (length(PIN_PRICE_EVENT_MS G) - length(replace(PIN_PRICE_E VENT_MSG, pin_delim, '')))/length(pin_delim) occurences into n_count
from dual;
DBMS_OUTPUT.put_line ('n_count 2 :' || n_count);
END;
DECLARE
n_count varchar2(1000) :=0;
PIN_PRICE_EVENT_MSG CLOB;
pin_delim varchar2(10) := '||';
BEGIN
PIN_PRICE_EVENT_MSG := '<?xml version="1.0"?><PDATA><HDR
select (length(PIN_PRICE_EVENT_MS
from dual;
DBMS_OUTPUT.put_line ('n_count 2 :' || n_count);
END;
select length('500 Oracle Parkway, Redwood Shores, CA') - length(translate('500 Oracle Parkway, Redwood Shores, CA', 'A,', 'A')) occurences from dual;