1

The following string has some variables inside:

sText := '%CUSTOMER_LASTNAME%%CUSTOMER_PRENAME% - LANG: %LANGUAGE%'

I made a custom SPLIT_STRING function and want to get each variable in the String:

sStr := SPLIT_STRING(sText,'%');

What I now got in loop is:

  • null
  • CUSTOMER_LASTNAME
  • null
  • CUSTOMER_PRENAME,
  • '- Lang':
  • LANGUAGE
  • null

What I need:

  • CUSTOMER_LASTNAME
  • CUSTOMER_PRENAME
  • LANGUAGE

Can I perform a split string with an RegExp or how to do this?

TIA frgtv10

4

1 回答 1

2

Can I perform a split string with an RegExp

Yes, you can. Here is an example of how it can be done.

    SQL> with t1(col) as(
      2    select '%CUSTOMER_LASTNAME%%CUSTOMER_PRENAME%- LANG: %LANGUAGE%' from dual
      3  )
      4  , ocrs as(
      5     select level as ocr
      6       from ( select max(regexp_count(col, '%[^%]+%')) mxo
      7                from t1
      8             ) s
      9     connect by level <= s.mxo
     10  )
     11  select ltrim(rtrim(regexp_substr(col, '%[^%]+%', 1, o.ocr), '%'), '%') as res
     12    from t1
     13    cross join ocrs o
     14  ;

Result:

    RES
    --------------------
    CUSTOMER_LASTNAME
    CUSTOMER_PRENAME
    LANGUAGE

SQLFiddle Demo

于 2013-09-06T12:27:07.073 回答