Quantcast
OracleBrains.Com header image 2

Working Example of REGEXP_LIKE

September 18th, 2007 by Rajender Singh · No Comments

Scenario From Oracle Forum

I have to select data from table which has the words both ‘help’ and ‘window’

eg: window.open(’help’) this type of data should be selected.

Both the words are mandatory.

Eg:window.open(’hai’) should not be selected.

This is not working
select * from employee_comment WHERE regexp_like(text,’window*help’) ;

Solution which I gave:

WITH data_Set AS
(
SELECT 1 row_no, ’shdhd dhdh window ddjfdh help’ text_col FROM dual
UNION ALL
SELECT 2 row_no, ’shdhd dhdh help window ddjfdh’ text_col FROM dual
UNION ALL
SELECT 3 row_no, ‘window.open(”hai”) ‘ text_col FROM dual
UNION ALL
SELECT 4 row_no, ‘window.open(”help”)’ text_col FROM dual
)
SELECT row_no FROM data_set
WHERE REGEXP_LIKE(text_col,’.*window.*help.*’)
/

Improved solution after feedback from Volder

WITH data_Set AS
(
SELECT 1 row_no, ’shdhd dhdh window ddjfdh help’ text_col FROM dual
UNION ALL
SELECT 2 row_no, ’shdhd dhdh help window ddjfdh’ text_col FROM dual
UNION ALL
SELECT 3 row_no, ‘window.open(”hai”) ‘ text_col FROM dual
UNION ALL
SELECT 4 row_no, ‘window.open(”help”)’ text_col FROM dual
)
SELECT row_no FROM data_set
WHERE REGEXP_LIKE(text_col,’.*window.*help.*|.*help.*window.*’)
/


Tags: Interesting Coding Showcase · SQL and PL/SQL

0 responses so far ↓

  • There are no comments yet...Kick things off by filling out the form below.

Leave a Comment

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Comment moderation is enabled. Your comment may take some time to appear.