Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to replace multiple LIKE operators with one REGEXP_LIKE

PavolAlcoholJul 22 2013 — edited Jul 22 2013

Hi All,

One column in m y table can contains string values something like XML nodes with attributes. Here's example:

<tag type="L" value="19" state="in"></tag>

<tag value="20" type="L" state="notIn"></tag>

<tag value="21" state="in" type="X"></tag>

I'm filtering rows which meet following rules:

-begin with '<tag'

-end with '</tag>'

-contain expression 'type="L"'

-contain expression 'state="in"' or 'state="notIn"'

My where clause to filter necessary rows is following:

WHERE SQLCMD LIKE '<tag%</tag>'

AND SQLCMD LIKE '%type="L"%'

AND (SQLCMD LIKE '%state="in"%' OR SQLCMD LIKE '%state="notIn"%');

Such clause will return first two rows from my example.

Now I need to transfrom my long where to just one REGEXP_LIKE condition and check performance  impact.

My main problem is to write optional order of mandatory attributes in such reqular expression. Can  somebody help me?

I don't preffer using the XML functions like XMLPATH, XMLTYE, EXTRACTVALUE due to slower performance.

thanks

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 19 2013
Added on Jul 22 2013
6 comments
854 views