Getting a word which contains some strings [message #629403] |
Mon, 08 December 2014 11:09 |
|
jaggy
Messages: 15 Registered: November 2014 Location: India
|
Junior Member |
|
|
I have a sentence which consists of different words and I have some letter of a word from the sentence. Can some one please help me how I can get that word which contains those letters. I have tried with substr,instr but no result.
Eg,
Sentence:
I know English very well.
I have the some letters like "gli", I need some oracle query which can give the total word English.
|
|
|
|
|
|
|
Re: Getting a word which contains some strings [message #629609 is a reply to message #629596] |
Fri, 12 December 2014 03:29 |
|
Shreya Aggarwal
Messages: 4 Registered: December 2014
|
Junior Member |
|
|
Hi Bill,
In case we want all the matching words in a sentence then we can use following query:
WITH string_tab
AS (SELECT 1 id,
'I watched English Winglish.' val
FROM dual
UNION
SELECT 2 ID,
'I know English very well.' val
FROM dual),
--seaching for the given string in the sentence
searched_string
AS (SELECT id,
LEVEL
occurance,
val,
Regexp_substr(val, '[[:alpha:]]*(gli)[[:alpha:]]*', 1, LEVEL,
'i')
VALUE
FROM string_tab
CONNECT BY LEVEL < Regexp_count(val, '(gli)') + 1
AND PRIOR id = id
AND PRIOR dbms_random.value IS NOT NULL)
--grouping the searched words
SELECT id,
val,
Listagg (value, ',')
within GROUP ( ORDER BY occurance ) Words
FROM searched_string
GROUP BY id,
val;
This code will return the comma separated list of words containing that string.
|
|
|