0

I have a input column with below values.

1.2%
111.00$
$100.00
aa
ss

Output expected

1.2
111.00
100.00
null
null

I am trying to use REGEXP_REPLACE and tried replacing every character that is not a digit or "." so that 1.2% will become 1.2. Here is the query I tried but this didn't work.

regexp_replace('%1.aa2', '[^[\d|\.]]', '') 

Can anyone suggest how to do that? and what I am doing wrong? I am working on Oracle 11.2 database with pl/sql developer.

Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523
Nitesh
  • 490
  • 3
  • 6
  • 15

2 Answers2

1

Use POSIX class for matching digit chars ie [:digit:]. So this negated class [^[:digit:].] should match any character but not of dot or digit.

regexp_replace('%1.aa2', '[^[:digit:].]', '') 
Avinash Raj
  • 172,303
  • 28
  • 230
  • 274
1

You can use the [^0-9.] regex and replace with empty string:

with testdata(txt) as (
  select 'ss' from dual
  union
  select 'aa' from dual
  union
  select '$100.00'      from dual
  union
  select '111.00$'             from dual
  union
  select '1.2%'             from dual
)
select regexp_replace(txt, '[^0-9.]', '')
from testdata;

Result of an SQL fiddle:

enter image description here

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563