DECODE函数可用于减少处理时间。例如,以下查询可以更高效地使用DECODE:
SELECT COUNT(DECODE(DEPT_NO, 0020, 'X', NULL)) AS D0020_COUNT, COUNT(DECODE(DEPT_NO, 0030, 'X', NULL)) AS D0030_COUNT, SUM(DECODE(DEPT_NO, 0020, SAL, NULL)) AS D0020_SAL, SUM(DECODE(DEPT_NO, 0030, SAL, NULL)) AS D0030_SAL
FROM EMP
WHERE ENAME LIKE 'SMITH%';