Search notes:

Oracle: UTL_CALL_STACK.DYNAMIC_DEPTH

The dynamic depth is increased when a subprogram (function or procedure) is called and decreased again when the subprogram returns to the caller.
The dynamic depth of an SQL statement that is not executed in PL/SQL context is 0:
select
   utl_call_stack.dynamic_depth
from
   dual;
In anonymous block, the depth is 1:
begin
   dbms_output.put_line(utl_call_stack.dynamic_depth);
end;
/
Calling a procedure increases the depth by 1. The following example prints 2:
create or replace procedure tq84_print_dyn_depth as begin
   dbms_output.put_line(utl_call_stack.dynamic_depth);
end;
/

begin
   tq84_print_dyn_depth;
end;
/
This example prints 3:
create or replace procedure tq84_wrap_dyn_depth as begin
   tq84_print_dyn_depth;
end;
/

begin
   tq84_wrap_dyn_depth;
end;
/
Nested procedures also increase the depth: the following example prints 4:
create or replace procedure tq84_nesting_procs as
   procedure nested_proc as begin
      tq84_print_dyn_depth;
   end;
begin
-- tq84_print_dyn_depth;
   nested_proc; 
end;
/

begin
   tq84_nesting_procs;
end;
/
Cleaning up:
drop procedure tq84_nesting_procs;
drop procedure tq84_wrap_dyn_depth;
drop procedure tq84_print_dyn_depth;

See also

utl_call_stack

Index