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)
CREATE OR REPLACE PACKAGE department_api IS
PROCEDURE del (in_department_id IN departments.department_id%TYPE);
END department_api;
/
CREATE OR REPLACE PACKAGE BODY department_api IS
FUNCTION does_exist (in_department_id IN departments.department_id%TYPE)
RETURN BOOLEAN IS
l_return PLS_INTEGER;
BEGIN
<<check_row_exists>>
BEGIN
SELECT 1
INTO l_return
FROM departments
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 departments.department_id%TYPE) IS
BEGIN
IF does_exist(in_department_id) THEN
NULL;
END IF;
END del;
END department_api;
/
Example (good)
CREATE OR REPLACE PACKAGE department_api IS
PROCEDURE del (in_department_id IN departments.department_id%TYPE);
END department_api;
/
CREATE OR REPLACE PACKAGE BODY department_api IS
FUNCTION does_exist (in_department_id IN departments.department_id%TYPE)
RETURN BOOLEAN;
PROCEDURE del (in_department_id IN departments.department_id%TYPE) IS
BEGIN
IF does_exist(in_department_id) THEN
NULL;
END IF;
END del;
FUNCTION does_exist (in_department_id IN departments.department_id%TYPE)
RETURN BOOLEAN IS
l_return PLS_INTEGER;
BEGIN
<<check_row_exists>>
BEGIN
SELECT 1
INTO l_return
FROM departments
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;
END department_api;
/