phsjhxx
phsjhxx
phsjhxx
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
5.4.2 CASE / IF / DECODE / NVL / NVL2 / COALESCE<br />
32. Try to use CASE rather than an IF statement with multiple ELSIF paths.<br />
[CodeXpert 4213]<br />
Reason: IF statements containing multiple ELSIF tend to become complex quickly.<br />
Example:<br />
-- bad<br />
IF l_color = 'red'<br />
THEN<br />
...<br />
ELSIF l_color = 'blue'<br />
THEN<br />
...<br />
ELSIF l_color = 'black'<br />
THEN<br />
...<br />
-- Good<br />
CASE l_color<br />
WHEN 'red' THEN ...<br />
WHEN 'blue' THEN ...<br />
WHEN 'black' THEN ...<br />
END<br />
33. Try to use CASE rather than DECODE.<br />
[CodeXpert 5816]<br />
Reason: DECODE is an old function that has been replaced by the easier-tounderstand<br />
and more common CASE function. Contrary to the DECODE<br />
statement CASE may also be used directly within PL/SQL.<br />
Example:<br />
-- Bad<br />
BEGIN<br />
...<br />
SELECT DECODE(dummy, 'A', 1<br />
INTO l_result<br />
FROM dual;<br />
, 'B', 2<br />
, 'C', 3<br />
, 'D', 4<br />
, 'E', 5<br />
, 'F', 6<br />
, 7)<br />
PL/SQL Coding Guidelines 29