DECODE(
NVL(COMMISSION_PCT),
COMMISSION_PCT < 0,2,'BAD',COMMISSION_PCT > 0,2,'GOOD'
)
Your query is syntactically incorrect.
NVL
syntax is incomplete
- You have a typo in the decimal number, a comma instead of dot.
- DECODE syntax doesn't support comparisons.
For your requirement, you could use CASE expression which is verbose and easy to interpret.
Using CASE
For example, using the standard EMP table in SCOTT schema:
SQL> SELECT ename,
2 sal,
3 CASE
4 WHEN NVL(comm, 0) < 0.2
5 THEN 'BAD'
6 WHEN NVL(comm, 0) > 0.2
7 THEN 'GOOD'
8 END CommissionResult
9 FROM emp;
ENAME SAL COMM
---------- ---------- ----
SMITH 800 BAD
ALLEN 1600 GOOD
WARD 1250 GOOD
JONES 2975 BAD
MARTIN 1250 GOOD
BLAKE 2850 BAD
CLARK 2450 BAD
SCOTT 3000 BAD
KING 5000 BAD
TURNER 1500 BAD
ADAMS 1100 BAD
JAMES 950 BAD
FORD 3000 BAD
MILLER 1300 BAD
14 rows selected.
However, if you must use DECODE, then you need to use SIGN to have the same functionality.
Using DECODE
SQL> SELECT ename,
2 sal,
3 DECODE( SIGN(NVL(comm, 0) - 0.2), -1, 'BAD', +1, 'GOOD') CommissionResult
4 FROM emp;
ENAME SAL COMM
---------- ---------- ----
SMITH 800 BAD
ALLEN 1600 GOOD
WARD 1250 GOOD
JONES 2975 BAD
MARTIN 1250 GOOD
BLAKE 2850 BAD
CLARK 2450 BAD
SCOTT 3000 BAD
KING 5000 BAD
TURNER 1500 BAD
ADAMS 1100 BAD
JAMES 950 BAD
FORD 3000 BAD
MILLER 1300 BAD
14 rows selected.