Best unofficial Apache Server developers community
Username
Forgot password?
Sign in with Twitter account
Sign in with Facebook account

How to extract pattern from a table in Oracle 11g

0

40 views

I want to extract text from a column using regular expressions in Oracle 11g. I have 2 queries that do the job but I'm looking for a (cleaner/nicer) way to do it. Maybe combining the queries into one or a new equivalent query. Here they are:

Query 1: identify rows that match a pattern:

select column1 from table1 where regexp_like(column1, pattern);

Query 2: extract all matched text from a matching row.

select regexp_substr(matching_row, pattern, 1, level) 
from dual
connect by level < regexp_count(matching_row, pattern);

I use PL/SQL to glue these 2 queries together, but it's messy and clumsy. How can I combine them into 1 query. Thank you.

UPDATE: sample data for pattern 'BC':

row 1: ABCD
row 2: BCFBC
row 3: HIJ
row 4: GBC

Expected result is a table of 4 rows of 'BC'.

asked June 22, 2011 10:54 am CDT
posted via StackOverflow

0 Answers

Be the first to answer this question

Join with account you already have


Sign in with Twitter account
Sign in with Facebook account
Sign in with Google Friend Connect

Preview
Similar questions