Skip to content

G-7120: Always add the name of the program unit to its end keyword.

Minor

Maintainability

Reason

It's a good alternative for comments to indicate the end of program units, especially if they are lengthy or nested.

Example (bad)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
create or replace package body employee_api is
   function employee_by_id(in_employee_id in employees.employee_id%type)
      return employees%rowtype is
      r_employee employees%rowtype;
   begin
      select *
        into r_employee
        from employees
       where employee_id = in_employee_id;

      return r_employee;
   exception
      when no_data_found then
         null;
      when too_many_rows then
         raise;
   end;
end;
/

Example (good)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
create or replace package body employee_api is
   function employee_by_id(in_employee_id in employees.employee_id%type)
      return employees%rowtype is
      r_employee employees%rowtype;
   begin
      select *
        into r_employee
        from employees
       where employee_id = in_employee_id;

      return r_employee;
   exception
      when no_data_found then
         null;
      when too_many_rows then
         raise;
   end employee_by_id;
end employee_api;
/