Skip to content

G-2120: Try to have a single location to define your types.

Minor

Changeability

Reason

Single point of change when changing the data type. No need to argue where to define types or where to look for existing definitions.

A single location could be either a type specification package or the database (database-defined types).

Example (bad)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
create or replace package body my_package is
   procedure my_proc is
      subtype big_string_type is varchar2(1000 char);
      l_note big_string_type;
   begin
      l_note := some_function();
      do_something(l_note);
   end my_proc;
end my_package;
/

Example (good)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
create or replace package types_up is
   subtype big_string_type is varchar2(1000 char);
end types_up;
/

create or replace package body my_package is
   procedure my_proc is
      l_note types_up.big_string_type;
   begin
      l_note := some_function();
      do_something(l_note);
   end my_proc;
end my_package;
/