Small timer utility
create or replace package tmr authid definer is
procedure capture;
function elapsed return number;
procedure show_elapsed;
end tmr;
create or replace package body tmr is
last_timing number := null;
procedure capture is
begin
last_timing := DBMS_UTILITY.GET_CPU_TIME;
end;
function elapsed return number is
begin
return ( mod(DBMS_UTILITY.GET_CPU_TIME - last_timing + POWER(2, 32), POWER(2, 32)) );
end;
procedure show_elapsed is
begin
DBMS_OUTPUT.PUT_LINE(elapsed);
end;
end tmr;
Static PL/SQL
declare
n number;
begin
commit;
tmr.capture;
for indx in 1..1000000 loop
n := n + indx;
end loop;
dbms_output.put_line('Static after computing ' || n);
tmr.show_elapsed;
end;
Dynamic PL/SQL
declare
n number;
begin
commit;
tmr.capture;
for indx in 1..1000000 loop
execute immediate 'begin :n := :n + :i; end;'
using in out n, in indx;
end loop;
dbms_output.put_line('Dynamic after computing ' || n);
tmr.show_elapsed;
end;
create or replace package g authid definer is
n number;
end;
/
Static SQL with global variable
begin
commit;
tmr.capture;
for indx in 1..1000000 loop
g.n := g.n + indx;
end loop;
dbms_output.put_line('Static after computing ' || g.n);
tmr.show_elapsed;
end;
/
Dynamic PL/SQL with global variable
begin
commit;
tmr.capture;
for indx in 1..1000000 loop
execute immediate 'begin g.n := g.n + :i; end;'
using in indx;
end loop;
dbms_output.put_line('Dynamic after computing ' || g.n);
tmr.show_elapsed;
end;
/