decode

The decode function returns an expression based on the first condition in the specified list that evaluates to true.

Category

Lookup

Return value

Expression or default expression

Returns the value associated with the first <condition> that evaluates to true. The data type of the return value is the data type of the first <expression_if_true>.

If the data type of any subsequent <expression_if_true> or <other_expression> is not convertible to the data type of the first <expression_if_true>, this application produces an error at validation. If the data types are convertible but do not match, a warning appears at validation.

Where

<condition>

Condition that evaluates to true or false.

<expression_if_true>

Value that the function returns if the first <condition> evaluates to true.

<other_expression>

Expression that the function returns if none of the conditions in the <condition> and <expression_if_true> lists evaluate to true. You must specify a value for <other_expression>.

Tips for Using Decode

Use decode in place of ifthenelse, which is not supported. The decode function is less error-prone than nested “if else” functions.

To improve performance, this application pushes this function to the database server when possible. Thus, the database server evaluates the decode function.

Use the decode function to apply multiple conditions when you map columns or select columns. For more flexible control over conditions in a script, use IF from the Keyword list in the Advanced Rule Editor.

If a condition compares a varchar value with trailing blanks, the decode function ignores the trailing blanks.

To compare a NULL value (NULL constant or variable that contains a NULL constant), use IS NULL or IS NOT NULL from the Operator list in the Advanced Rule Editor. If you use the Equal (=) or Not equal to (<>) operator, the comparison against a NULL value always evaluates to FALSE.

When you use decode in the Advanced Expression Editor for a view, add additional <other_expression> and <expression_if_true> parameters to the function by selecting Add Condition.