User Tools

Site Tools


Sidebar

**HPL/SQL is included to Apache Hive since version 2.0** * [[home|Home]]\\ * [[why|Why HPL/SQL]]\\ * [[features|Key Features]]\\ * [[start|Get Started]]\\ * [[doc|HPL/SQL Reference]]\\ * [[download|Download]]\\ * [[new|What's New]]\\ * [[about|About]]

decode

====== DECODE Function - PL/HQL Reference ====== DECODE function allows you to implement IF-THEN-ELSE logic. **Syntax:** <code language=sql> DECODE(expr, when_exp1, then_expr1 [, ...n] [, else_expr]) </code> **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**: <code language=sql> 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 </code> **Compatibility:** Oracle, IBM DB2 and Teradata **Version**: PL/HQL 0.3.1 See also: * [[case|CASE Expression]]