This is a technique to get the individual words in a phrase.
It is based on the use of:
CREATE OR REPLACE TYPE typ_word AS OBJECT
(
text VARCHAR2(64)
)
/
CREATE OR REPLACE TYPE TYP_word_COL
AS TABLE OF TYP_word;
/
The function itself:
CREATE OR REPLACE FUNCTION get_words (v_sentence VARCHAR2)
RETURN typ_word_col PIPELINED
AS
occurence PLS_INTEGER := 1;
aword VARCHAR2 (64);
BEGIN
LOOP
aword := REGEXP_SUBSTR (v_sentence, '\w+', 1, occurence);
IF aword IS NULL
THEN
RETURN;
END IF;
PIPE ROW (NEW typ_word(aword));
occurence := occurence + 1;
END LOOP;
END;
/
It is based on the use of:
- PIPELINED functions, and
- Regular Expressions
CREATE OR REPLACE TYPE typ_word AS OBJECT
(
text VARCHAR2(64)
)
/
CREATE OR REPLACE TYPE TYP_word_COL
AS TABLE OF TYP_word;
/
The function itself:
CREATE OR REPLACE FUNCTION get_words (v_sentence VARCHAR2)
RETURN typ_word_col PIPELINED
AS
occurence PLS_INTEGER := 1;
aword VARCHAR2 (64);
BEGIN
LOOP
aword := REGEXP_SUBSTR (v_sentence, '\w+', 1, occurence);
IF aword IS NULL
THEN
RETURN;
END IF;
PIPE ROW (NEW typ_word(aword));
occurence := occurence + 1;
END LOOP;
END;
/
No comments:
Post a Comment