rules repository

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

Severity Error Check Free

Reason

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

Example

Non-Compliant Example

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;
/
Issues
LineColumnMessage
419Missing target columns in insert statement.

Compliant Solution - ★★★★★

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

References