G-3110
🆓Error
Always specify the target columns when coding an insert statement.
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
| Line | Column | Message |
|---|---|---|
| 4 | 19 |
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
- same as Trivadis G-3110
- same as plsqlopen:InsertWithoutColumns
- same as plsql:S1745