Skip to content

Instantly share code, notes, and snippets.

@velll
Created May 18, 2016 15:08
Show Gist options
  • Save velll/11030dca30fae3582d87c4f732ef14c3 to your computer and use it in GitHub Desktop.
Save velll/11030dca30fae3582d87c4f732ef14c3 to your computer and use it in GitHub Desktop.
Replace non-numerical characters: regex vs translate. Oracle 11G
create table million_rows (no number)
/
insert into million_rows select level from dual connect by level <= 200000
/
insert into million_rows select 200000 + level from dual connect by level <= 200000
/
insert into million_rows select 400000 + level from dual connect by level <= 200000
/
insert into million_rows select 600000 + level from dual connect by level <= 200000
/
insert into million_rows select 800000 + level from dual connect by level <= 200000
/
commit
/
declare
ts_start timestamp := systimestamp;
ts_finish timestamp;
vch varchar2(100);
begin
for rl in (
select 'sdogsafgljn1-r01rlknsd' || no line
from million_rows)
loop
vch := regexp_replace(rl.line, '\D');
end loop;
ts_finish := systimestamp;
raise_application_error(-20100, 'REGEX: 1000000 in ' || (ts_finish - ts_start));
end;
declare
ts_start timestamp := systimestamp;
ts_finish timestamp;
vch varchar2(100);
begin
for rl in (
select 'sdogsafgljn1-r01rlknsd' || no line
from million_rows)
loop
vch := translate(rl.line, '#' || translate (rl.line,'#0123456789','#'),'#');
end loop;
ts_finish := systimestamp;
raise_application_error(-20100, 'TRANS: 1000000 in ' || (ts_finish - ts_start));
end;
REGEX: 1000000 in +000000000 00:00:15.576932000
TRANS: 1000000 in +000000000 00:00:16.577972000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment