G-7220: Always use forward declaration for private functions and procedures.
Minor
Changeability
Reason
Having forward declarations allows you to order the functions and procedures of the package in a reasonable way.
Example (bad)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | create or replace package department_api is procedure del (in_department_id in department.department_id%type); end department_api; / create or replace package body department_api is function does_exist (in_department_id in department.department_id%type) return boolean is l_return pls_integer; begin <<check_row_exists>> begin select 1 into l_return from department where department_id = in_department_id; exception when no_data_found or too_many_rows then l_return := 0; end check_row_exists; return l_return = 1; end does_exist; procedure del (in_department_id in department.department_id%type) is begin if does_exist(in_department_id) then null; end if; end del; end department_api; / |
Example (good)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | create or replace package department_api is procedure del (in_department_id in department.department_id%type); end department_api; / create or replace package body department_api is function does_exist (in_department_id in department.department_id%type) return boolean; procedure del (in_department_id in department.department_id%type) is begin if does_exist(in_department_id) then null; end if; end del; function does_exist (in_department_id in department.department_id%type) return boolean is l_return pls_integer; k_exists constant pls_integer := 1; k_something_wrong constant pls_integer := 0; begin <<check_row_exists>> begin select k_exists into l_return from department where department_id = in_department_id; exception when no_data_found or too_many_rows then l_return := k_something_wrong; end check_row_exists; return l_return = k_exists; end does_exist; end department_api; / |