User Tools

Site Tools


Sidebar

HPL/SQL is included to Apache Hive since version 2.0

decode

DECODE Function - PL/HQL Reference

DECODE function allows you to implement IF-THEN-ELSE logic.

Syntax:

DECODE(expr, when_exp1, then_expr1 [, ...n] [, else_expr]) 

Notes:

  • If expr is NULL it will match the first when_exprN that is NULL
  • If when_exprN is not matched then_exprN is not evaluated

Examples:

DECLARE var1 INT DEFAULT 3;
 
PRINT DECODE (var1, 1, 'A', 2, 'B', 3, 'C');       -- Result: C
PRINT DECODE (var1, 1, 'A', 2, 'B', 'C');          -- Result: C
 
SET var1 = NULL;
PRINT DECODE (var1, 1, 'A', 2, 'B', NULL, 'C');    -- Result: C  

Compatibility: Oracle, IBM DB2 and Teradata

Version: PL/HQL 0.3.1

See also: