I have Learnt about PRAGMA INLINE 11g feature , but I am not able to distinguish how it actually optimize my code.
I have written a piece of code.
create or replace package test12
is
procedure getdata (p_job IN emp.job%TYPE
,p_total OUT number);
end test12;
/
create or replace package body test12
is
PROCEDURE total(p_empno IN EMP.EMPNO%TYPE
,p_total OUT integer)
IS
BEGIN
select sal into p_total from emp where empno=p_empno;
END total;
procedure getdata (p_job IN emp.job%TYPE
,p_total OUT number)
IS
type cur is ref cursor;
v_cur cur;
v_emp emp.empno%TYPE;
v_total integer:=0;
BEGIN
for i in 1..100000
loop
open v_cur for select empno from emp where job=p_job;
loop
fetch v_cur into v_emp;
exit when v_cur%notfound;
--PRAGMA INLINE(total,'YES');
total(v_emp,v_total);
p_total:=p_total+v_total;
end loop;
close v_cur;
end loop;
END getdata;
end test12;
/
declare
v_total integer;
v_start integer;
v_end integer;
begin
v_start:=DBMS_UTILITY.GET_TIME;
test12.getdata('CLERK',v_total);
v_end :=DBMS_UTILITY.GET_TIME;
v_total:=v_end-v_start;
dbms_output.put_line('time is '||v_total);
end;
/
Now if I run without pragma inline it gives me the following time
First Run : time is 3573
Second Run: time is 3571
Third Run : time is 3554
Now if I run with pragma inline it gives me the following time
First Run : time is 3471
Second Run: time is 3489
Third Run : time is 3482
But here I didn’t see any significant difference between the two. What might be the reason for that?
The amount of time spent just to call the procedure is almost 0. There’s very little to optimize here. I’m surprised you saw any improvement at all. 99.9% of the execution time is probably spent in SQL, not PL/SQL.