Skip to content

Commit 9d618b5

Browse files
committed
Fix #85 - Warn about NULL issues in rule G-4220
1 parent bc849ca commit 9d618b5

File tree

1 file changed

+23
-1
lines changed
  • docs/4-language-usage/4-control-structures/2-case-if-decode-nvl-nvl2-coalesce

1 file changed

+23
-1
lines changed

docs/4-language-usage/4-control-structures/2-case-if-decode-nvl-nvl2-coalesce/g-4220.md

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

66
## Reason
77

8-
`DECODE` is an ORACLE specific function hard to understand and restricted to SQL only. The “newer” `CASE` function is much more common has a better readability and may be used within PL/SQL too.
8+
`decode` is an ORACLE specific function hard to understand and restricted to SQL only. The “newer” `case` function is much more common, has a better readability and may be used within PL/SQL too. Be careful that `decode` can handle `null` values, which the simple `case` cannot - for such cases you must use the searched `case` and `is null` instead.
99

1010
## Example (bad)
1111

@@ -27,4 +27,26 @@ select case dummy
2727
else 0
2828
end
2929
from dual;
30+
```
31+
32+
## Example (bad)
33+
34+
``` sql
35+
select decode(dummy, 'X', 1
36+
, 'Y', 2
37+
, null, -1
38+
, 0)
39+
from dual;
40+
```
41+
42+
## Example (good)
43+
44+
``` sql
45+
select case
46+
when dummy = 'X' then 1
47+
when dummy = 'Y' then 2
48+
when dummy is null then -1
49+
else 0
50+
end
51+
from dual;
3052
```

0 commit comments

Comments
 (0)