DEV Community

AntDB
AntDB

Posted on

AntDB-Oracle Compatibility Developer’s Manual P3–72

DECODE

decode(condition,x1, y1, x2, y2, x3,y3 [,xn, yn] ……, default_value)

The meaning of the function is as follows.

IF condition=x1 THEN

RETURN(y1)

ELSIF condition=x2 THEN

RETURN(y2)

......

ELSIF condition=xn THEN

RETURN(yn)

ELSE

RETURN(default_value)

END IF

Example:

select EMPNO, decode(DEPTNO, 10, 1, 20, 2, 30,3, 0) from emp;
 EMPNO | DECODE(DEPTNO, 10, 1, 20, 2, 30,3, 0)  
-------+----------------------------------------
  7521 |                                      3
  7566 |                                      2
  7654 |                                      3
  7782 |                                      1
  7788 |                                      2
  7839 |                                      1
  7844 |                                      3
  7900 |                                      3
  7902 |                                      2
  7934 |                                      1
  7876 |                                      2
  7469 |                                      2
  7698 |                                      3
  7369 |                                      2
  7499 |                                      3
(15 rows)
Enter fullscreen mode Exit fullscreen mode

Top comments (0)