REGEXP Conversion

Giganews Newsgroups
Subject: REGEXP Conversion
Posted by:  Dave (david.c.wats…@gmail.com)
Date: Wed, 10 Feb 2010

Hi,

Is anyone good at converting the following sql statement's LIKE
clauses into 1 coherent REGEXP_LIKE?  I came up with a couple of
solutions but am interested in seeing if anyone has a more efficient
way then what I produced.

Thanks,
Dave

SELECT *
  FROM demo_table
WHERE TRIM (code) = TRIM ('918')
    OR TRIM (REGEXP_REPLACE (code, ' *, *', ',')) LIKE '%,' || TRIM
('918')
    OR TRIM (REGEXP_REPLACE (code, ' *, *', ',')) LIKE TRIM ('918') ||
',%'
    OR TRIM (REGEXP_REPLACE (code, ' *, *', ',')) LIKE '%,' || TRIM
('918') || ',%';

Code Column has data stored with 1 to many codes, seperated by
commas...

i.e. 829,58,189,918

Replies