For SQL, I checked this with the following script:
set timing on select sum(length(x)) from ( select translate('(<FIO>)', '()[]', '----') x from ( select * from dual connect by level <= 2000000 ) ); select sum(length(x)) from ( select regexp_replace('[(<FIO>)]', '[\(\)\[]|\]', '-', 1, 0) x from ( select * from dual connect by level <= 2000000 ) );
and found that the performance of translate and regexp_replace almost always the same, but it may be that the cost of other operations exceeds the cost of the functions I'm trying to test.
Next I tried the PL / SQL version:
set timing on declare x varchar2(100); begin for i in 1..2500000 loop x := translate('(<FIO>)', '()[]', '----'); end loop; end; / declare x varchar2(100); begin for i in 1..2500000 loop x := regexp_replace('[(<FIO>)]', '[\(\)\[]|\]', '-', 1, 0); end loop; end; /
Here, the translate version takes less than 10 seconds, and the regexp_replace version regexp_replace about 0.2 seconds - about 2 orders of magnitude faster (!)
Based on this result, I will use regular expressions much more often in my critical critical code - both SQL and PL / SQL.
Colin 't hart
source share