rules repository

G-2130

πŸ†“
Warning

Try to use subtypes for constructs used often in your code.

Variable β€’ Check

Reason

Single point of change when changing the data type.

Your code will be easier to read as the usage of a variable/constant may be derived from its definition.

Examples of possible subtype definitions:

TypeUsage
ora_name_typeObject corresponding to the Oracle Database naming conventions (table, variable, column, package, etc.).
max_vc2_typeString variable with maximal VARCHAR2 size.
array_index_typeBest fitting data type for array navigation.
id_typeData type used for all primary key (id) columns.

Example

Non-Compliant Example

create or replace package body my_package is
   procedure my_proc is
      l_note varchar2(1000 char);
   begin
      l_note := some_function();
      do_something(l_note);
   end my_proc;
end my_package;
/
Issues
LineColumnMessage
314Consider using a subtype for l_note.

Compliant Solution - β˜…β˜…β˜…β˜…β˜…

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;
/

References