----------------------------------------------------------------------------------- -- Create package specification ----------------------------------------------------------------------------------- create or replace PACKAGE timer IS -- package specification PROCEDURE start_timer; PROCEDURE end_timer; -- public modules FUNCTION get_timer_interval return number; author varchar2(10) := 'Sam'; -- public global variable END; / ----------------------------------------------------------------------------------- -- Create package body ----------------------------------------------------------------------------------- create or replace PACKAGE BODY timer AS -- package body start_time number := null; end_time number := null; -- private global variables PROCEDURE start_timer IS BEGIN start_time := DBMS_UTILITY.get_time( ); END; PROCEDURE end_timer IS BEGIN end_time := DBMS_UTILITY.get_time( ); END; FUNCTION get_timer_interval return number IS delta_time number := null; -- private local variable BEGIN delta_time := (end_time - start_time) * 10; -- value is in 100th of sec return delta_time; -- convert that to millisec END; END; / ----------------------------------------------------------------------------------- -- Use the package above ----------------------------------------------------------------------------------- DECLARE time_used number; BEGIN TIMER.start_timer( ); -- call procedure within a package for i in 1..1000000 loop null; -- nothing to do end loop; -- just killing time TIMER.end_timer( ); time_used := TIMER.get_timer_interval( ); DBMS_OUTPUT.put_line('Time elapsed: ' || time_used || ' millisec'); DBMS_OUTPUT.put_line('Author......: ' || timer.author ); -- access a package variable END;