This one is self-explanatory.
SQL> VAR s VARCHAR2(4000)
SQL> BEGIN
2 :s := 'The quick brown fox jumps over the lazy dog.';
3 END;
4 /
PL/SQL procedure successfully completed.
SQL> SET PAGES 100
SQL> SELECT REGEXP_SUBSTR(:s, '\w+', 1, LEVEL) words
2 FROM dual
3 CONNECT BY REGEXP_SUBSTR(:s, '\w+', 1, LEVEL) IS NOT NULL
4 /
WORDS
--------------------------------------------------------------
The
quick
brown
fox
jumps
over
the
lazy
dog
9 rows selected.
SQL> SET PAGES 100
SQL> VAR s VARCHAR2(4000)
SQL> VAR d VARCHAR2(4000)
SQL> BEGIN
2 :s := 'The^quick*brown fox(jumps)over!the~lazy dog?.';
3 :s := :s || 'The-quick[brown]fox+jumps{over}the\lazy"dog''';
4 :d := '^*.()!~ +[]{}\"''-';
5 -- to test the functionality
6 :d := :d || :d;
7 END;
8 /
PL/SQL procedure successfully completed.
SQL> COLUMN word FORMAT A62
SQL> SELECT word
2 FROM (
3 SELECT CASE
4 WHEN :d IS NULL
5 THEN :s
6 ELSE REGEXP_SUBSTR(
7 :s
8 , '[^'
9 || CASE WHEN INSTR(:d, ']') > 0 THEN ']' END
10 || REGEXP_REPLACE(:d, ']|-')
11 || CASE WHEN INSTR(:d, '-') > 0 THEN '-' END
12 || ']+'
13 , 1
14 , LEVEL
15 , 'm'
16 )
17 END word
18 FROM dual
19 WHERE :s IS NOT NULL
20 CONNECT BY
21 CASE
22 WHEN ( :d IS NULL
23 AND :s IS NOT NULL
24 AND LEVEL = 1
25 )
26 OR ( :d IS NOT NULL
27 AND :s IS NOT NULL
28 AND REGEXP_INSTR(
29 :s
30 , '[^'
31 || CASE WHEN INSTR(:d, ']') > 0 THEN ']' END
32 || REGEXP_REPLACE(:d, ']|-')
33 || CASE WHEN INSTR(:d, '-') > 0 THEN '-' END
34 || ']+'
35 , 1
36 , LEVEL
37 , 0
38 , 'm'
39 ) > 0
40 )
41 THEN 1
42 END = 1
43 )
44 WHERE word IS NOT NULL
45 /
WORD
--------------------------------------------------------------
The
quick
brown
fox
jumps
over
the
lazy
dog?
The
quick
brown
fox
jumps
over
the
lazy
dog
18 rows selected.
Monday, December 26, 2005
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment