Skip to content

Commit e414069

Browse files
committed
Fix #27 - Created rule G-7720: Never use multiple UPDATE OF in trigger event clause.
1 parent 5607a7c commit e414069

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

docs/4-language-usage/7-stored-objects/2-packages/g-7240.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
## Reason
77

8-
The purpose of the initialization block of a package body is to set initial values of the global variables of the package (initialize the package state). Although `RETURN` is syntactically allowed in this block, it makes no sense. If it is the last keyword of the block, it is superfluous. If it is not the last keyword, then all code after the `RETURN` is unreachable and thus dead code.
8+
The purpose of the initialization block of a package body is to set initial values of the global variables of the package (initialize the package state). Although `return` is syntactically allowed in this block, it makes no sense. If it is the last keyword of the block, it is superfluous. If it is not the last keyword, then all code after the `return` is unreachable and thus dead code.
99

1010
## Example (bad)
1111

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# G-7720: Never use multiple UPDATE OF in trigger event clause.
2+
3+
!!! bug "Blocker"
4+
Maintainability, Reliability, Testability
5+
6+
## Reason
7+
8+
A DML trigger can have multiple triggering events separated by `or` like `before insert or delete or update of some_column`. If you have multiple `update of` separated by `or`, only one of them (the last one) is actually used and you get no error message, so you have a bug waiting to happen. Instead you always should use a single `update of` with all columns comma-separated, or an `update` without `of` if you wish all columns.
9+
10+
## Example (bad)
11+
12+
``` sql
13+
create or replace trigger dept_br_u
14+
before update of department_id or update of department_name
15+
on departments for each row
16+
begin
17+
-- will only fire on updates of department_name
18+
insert into departments_log (department_id
19+
,department_name
20+
,modification_date)
21+
values (:old.department_id
22+
,:old.department_name
23+
,sysdate);
24+
end;
25+
/
26+
```
27+
28+
## Example (good)
29+
30+
``` sql
31+
create or replace trigger dept_br_u
32+
before update of department_id, department_name
33+
on departments for each row
34+
begin
35+
insert into departments_log (department_id
36+
,department_name
37+
,modification_date)
38+
values (:old.department_id
39+
,:old.department_name
40+
,sysdate);
41+
end;
42+
/
43+
```

0 commit comments

Comments
 (0)