G-2130
🆓Warning
Try to use subtypes for constructs used often in your code.
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:
| Type | Usage |
|---|---|
ora_name_type | Object corresponding to the Oracle Database naming conventions (table, variable, column, package, etc.). |
max_vc2_type | String variable with maximal VARCHAR2 size. |
array_index_type | Best fitting data type for array navigation. |
id_type | Data 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
| Line | Column | Message |
|---|---|---|
| 3 | 14 |
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
- same as Trivadis G-2130