Home » SQL & PL/SQL » SQL & PL/SQL » regexp_replace - too heavy? (Oracle 11g)
regexp_replace - too heavy? [message #520916] Thu, 25 August 2011 07:32 Go to next message
ecivgamer
Messages: 147
Registered: May 2011
Location: Ukraine
Senior Member
I've got code for extracting numbers from varchar2 column:

with t1 as (
select 1 as acode, '100,00' as avalue from dual union all 
select 2 as acode, '100.00' as avalue from dual union all 
select 3 as acode, '100.00%' as avalue from dual union all 
select 4 as acode, '100.00perc' as avalue from dual 
           )
select acode, 
nvl(abs(regexp_replace(replace(avalue,',','.'),'[^1,2,3,4,5,6,7,8,9,0,.,]')),0) as avalue 
from t1


After few weeks of using we received complain, the Customer said that "sometimes" the procedure works too long. He said, it always works about two minutes, but "sometimes" it can work more than 24 hours! He investigated the issue and decided that the problem is regexp_replace (it's too heavy).

Could you please:

1) explain to me is it true that regexp_replace is too heavy

2) give me solution how do I receive the same result without regexp_replace.

Actually, I'm not trying to prove that regexp_replace is normal. It's a pity, but I can't discuss the issue with the Customer. I'm just trying to understand details for myself.

[Updated on: Thu, 25 August 2011 08:01] by Moderator

Report message to a moderator

Re: regexp_replace - too heavy? [message #520919 is a reply to message #520916] Thu, 25 August 2011 07:56 Go to previous messageGo to next message
joy_division
Messages: 4963
Registered: February 2005
Location: East Coast USA
Senior Member
What procedure?
Maybe you are updating and someone has the table locked?
There is no pertinent information in this post other than you are using regexp_replace.
Re: regexp_replace - too heavy? [message #520923 is a reply to message #520916] Thu, 25 August 2011 08:04 Go to previous messageGo to next message
Michel Cadot
Messages: 68773
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Quote:
2) give me solution how do I receive the same result without regexp_replace.

Please give us WITH WORDS what is the meaning of the expression.

Regards
Michel
Re: regexp_replace - too heavy? [message #520926 is a reply to message #520923] Thu, 25 August 2011 08:13 Go to previous messageGo to next message
ecivgamer
Messages: 147
Registered: May 2011
Location: Ukraine
Senior Member
Michel, avalue column in t1 table is varchar2, the task is to extract numbers only (with dot symbol if present). As it is varchar2 column, users can type "." (dot) or "," (comma), "%" (percent) and everything else. So before extracting numbers I replace "," into ".", then extract all numbers with dot, convert it into number (using abs or to_number). The last operation is nvl for possible null values.
Re: regexp_replace - too heavy? [message #520928 is a reply to message #520926] Thu, 25 August 2011 08:22 Go to previous messageGo to next message
cookiemonster
Messages: 13975
Registered: September 2008
Location: Rainy Manchester
Senior Member
I'm with Joy. I don't believe for a second that the time difference described can be due to this function.
You need to trace the session when it's running slow to see what's really going on.
Re: regexp_replace - too heavy? [message #520930 is a reply to message #520926] Thu, 25 August 2011 08:25 Go to previous message
Michel Cadot
Messages: 68773
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
First, a number should be in a number field.
If the format is always the one you gave you can do:
SQL> with t1 as (
  2  select 1 as acode, '100,00' as avalue from dual union all 
  3  select 2 as acode, '100.00' as avalue from dual union all 
  4  select 3 as acode, '100.00%' as avalue from dual union all 
  5  select 4 as acode, '100.00perc' as avalue from dual 
  6             )
  7  select acode, 
  8         nvl(to_number(translate(avalue,
  9                                 ','||translate(avalue,'%.,0123456789','%'),
 10                                 '.')),0) avalue
 11  from t1
 12  /
     ACODE     AVALUE
---------- ----------
         1        100
         2        100
         3        100
         4        100

Regards
Michel
Previous Topic: Re: Error in creating a trigger (split from unrelated thread by bb)
Next Topic: updating fields of higgest end_sys_id on table
Goto Forum:
  


Current Time: Thu Jan 01 17:45:29 CST 2026