Skip to content

G-3110: Always specify the target columns when coding an insert statement.

Blocker

Maintainability, Reliability

Reason

Data structures often change. Having the target columns in your insert statements will lead to change-resistant code.

Example (bad)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
create or replace package body dept_api is
   procedure ins_dept(in_dept_row in dept%rowtype) is
   begin
      insert into departments
      values (
         departments_seq.nextval
        ,in_dept_row.department_name
        ,in_dept_row.manager_id
        ,in_dept_row.location_id
      );
   end ins_dept;
end dept_api;
/

Example (good)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
create or replace package body dept_api is
   procedure ins_dept(in_dept_row in dept%rowtype) is
   begin
      insert into departments (
         department_id
        ,department_name
        ,manager_id
        ,location_id
      )
      values (
         departments_seq.nextval
        ,in_dept_row.department_name
        ,in_dept_row.manager_id
        ,in_dept_row.location_id
      );
   end ins_dept;
end dept_api;
/