[FIXED] Remove template text on regexp_replace in Oracle's SQL

Issue

I am trying to remove template text like &#x; or &#xx; or &#xxx; from long string

Note: x / xx / xxx - is number, The length of the number is unknown, The cell type is CLOB

for example:

SELECT 'H'ello wor±ld' FROM dual

A desirable result:

Hello world

I know that regexp_replace should be used, But how do you use this function to remove this text?


Solution

You can use

SELECT REGEXP_REPLACE(col,'&&#\d+;')       
  FROM t

where

  • & is put twice to provide escaping for the substitution character
  • \d represents digits and the following + provides the multiple occurrences of them
  • ending the pattern with ;

or just use a single ampersand ('&#\d+;') for the pattern as in the case of Demo , since an ampersand has a special meaning for Oracle, a usage is a bit problematic.



Answered By - Barbaros Özhan
Answer Checked By - Robin (sql.easybugfix Admin)

Related Posts

Post a Comment