What is the best way to extract words from a string? I already made something up because I found many ways and none of them looked 'simple'.
Let's assume there is a procedure called 'change_opening_hours'. This procedure has a time-range string input called 'v_perioden'.
This string looks like:
'10:00-12:00' OR
'10:00-12:00 14:00-16:00' OR
'10:00-12:00 14:00-16:00 18:00-22:00' etc
Now I already made something up myself to exstract every period of time from this input.
v_perioden VARCHAR2(50) := '10:00-12:00 14:00-18:00 22:00-24:00';
...
-- loop though time-periode depeningd
-- on amount of spaces
FOR i IN 0..REGEXP_COUNT(v_perioden, ' ') LOOP
-- first period
IF i = 0 THEN DBMS_OUTPUT.PUT_LINE(SUBSTR(v_perioden, 0, 11));
-- second period
ELSIF i = 1 THEN DBMS_OUTPUT.PUT_LINE(SUBSTR(v_perioden, 13, 11));
--thirt period
ELSIF i = 2 THEN DBMS_OUTPUT.PUT_LINE(SUBSTR(v_perioden, 25, 11));
END IF;
END LOOP;
Output:
10:00-12:00
14:00-18:00
22:00-24:00
Now this way is working fine, but it isn't that capable. I tried to find out how to extract words from a string on a space but this wasn't working out tho.