I'm working with some data which is stored in a VARCHAR2(4000) column and the data is mainly text comments but also contains dates within the text. I've written a query which uses SUBSTR and INSTR to pattern match and find a leading Text value prior to the date and then SUBST to return the date value which I then convert to a date using TO_DATE. This works well however I have a number of records that contain multiple comments and as such multiple dates. Using the above method I'm only able to specify the (n)th occurrence of this pattern, is there a way to return ALL dates when matched rather than only a single occurrence?
Here is an example of the data within the varchar column;
LOCKED ENTITY: ACCOUNT
LOCKED BY USER: ops
LOCKED AT: 31/05/2004 11:47
CUST NOTES: <Please enter explanation here>
Customer notes are entered here.
UNLOCKED ENTITY: ACCOUNT
UNLOCKED BY USER: ops
UNLOCKED AT: 31/05/2004 11:49
UNLOCK NOTES: <Please enter explanation here>
Test
LOCKED ENTITY: USER
LOCKED BY USER: ops
LOCKED AT: 31/05/2004 11:50
LOCK NOTES: <Please enter explanation here>
Test
UNLOCKED ENTITY: USER
UNLOCKED BY USER: ops
UNLOCKED AT: 24/08/2009 16:47
UNLOCKED NOTES: <Please enter explanation here>
Here's a simplified version of the query I'm using (All other irrelevant joins and columns removed for clarity);
select substr(VALUE, INSTR(VALUE,'LOCKED AT: ',1)+11, 10) as "DATE"
from tableA a
join tableB b
on a.id = b.id
where regexp_like (VALUE ,'ABC|DEF|GHI');
DATE
----------
31/05/2004
For the above Query I'd like to return all dates that follow the string 'LOCKED AT: ' eg;
DATE
----------
31/05/2004
31/05/2004
Any help would be appreciated. For info the DB version is Oracle 10g, I attempted to use REGEXP_COUNT to achieve something I had in my mind but only works with 11g onward.
Many Thanks