Table of Contents

Search

  1. Preface
  2. Understanding Data Types and Field Properties
  3. Designing Processes
  4. Using and Displaying Data
  5. Designing Guides
  6. Designing Process Objects
  7. Designing Service Connectors
  8. Using App Connections
  9. System Services, Listeners and Connectors
  10. Designing Human Tasks

Design

Design

decode

decode

Searches a column for a value that you specify. If the function finds the value, it returns a result value, which you define. You can build an unlimited number of searches within a decode function.
If you use decode to search for a value in a string column, you can either trim trailing blank characters with the rtrim function or include the blanks in the search string.

Syntax

util:decode(value, search1, result1, args, default)
The following table describes the arguments:
Argument
Required/
Optional
Description
value
Required
Passes the values that you want to search.
You can enter any valid transformation expression. You can pass any data type except Binary.
To pass a NULL value, you must specify an empty sequence in the following format:
()
search1
Required
Passes the values for which you want to search.
You can enter any valid transformation expression. You can pass any value with the same data type as the value argument. The search value must match the value argument. You cannot search for a portion of a value. Also, the search value is case sensitive.
For example, if you want to search for the string 'Halogen Flashlight' in a particular column, you must enter 'Halogen Flashlight, not just 'Halogen'. If you enter 'Halogen', the search does not find a matching value.
To pass a NULL value, you must specify an empty sequence in the following format:
()
result1
Required
The value that you want to return if the search finds a matching value.
You can enter any valid transformation expression and pass any data type except Binary.
To pass a NULL value, you must specify an empty sequence in the following format:
()
args
Required
Pairs of search values and result values separated by a comma.
For example, use the following syntax:
util:decode(value, search1, result1, search2, result2, searchn, resultn, default)
To pass a NULL value, you must specify an empty sequence in the following format:
()
default
Required
The value that you want to return if the search does not find a matching value.
You can enter any valid transformation expression and pass any data type except Binary.
To pass a NULL value, you must specify an empty sequence in the following format:
()

Return Value

result1
if the search finds a matching value.
default
value if the search does not find a matching value.
NULL if you omit the default argument and the search does not find a matching value.
Even if multiple conditions are met, decode returns the first matching result.

decode and data types

When you use decode, the data type of the return value is always the same as the data type of the result with the greatest precision.
For example, you have the following expression:
util:decode( CONST_NAME          'Five', 5,          'Pythagoras', 1.414213562,          'Archimedes', 3.141592654,          'Pi', 3.141592654 )
The return values in this expression are 5, 1.414213562, and 3.141592654. The first result is an integer, and the other results are decimal. The decimal data type has a greater precision than the integer data type. This expression always writes the result as a decimal value.
You cannot create a decode function with both string and numeric return values.
For example, the following expression is not valid:
util:decode( CONST_NAME          'Five', 5,          'Pythagoras', '1.414213562',          'Archimedes', '3.141592654',          'Pi', 3.141592654 )
When you validate the expression above, you receive the following error message:
Function cannot resolve operands of ambiguously mismatching datatypes.

Examples

You might use decode in an expression that searches for a particular ITEM_ID and returns the ITEM_NAME:
util:decode( ITEM_ID, 10, 'Flashlight',                  14, 'Regulator',                  20, 'Knife',                  40, 'Tank',                  'NONE' )
The following table lists some sample values and return values:
ITEM_ID  
RETURN VALUE
10
Flashlight
14
Regulator
17
NONE
20
Knife
25
NONE
NULL
NONE
40
Tank
The decode function returns the default value of NONE for items 17 and 25 because the search values did not match the ITEM_ID. Also, decode returns NONE for the NULL ITEM_ID.
The following expression tests multiple columns and conditions, evaluated in a top to bottom order for TRUE or FALSE:
util:decode( TRUE,         Var1 = 22, 'Variable 1 was 22!',         Var2 = 49, 'Variable 2 was 49!',         Var1 < 23, 'Variable 1 was less than 23.',         Var2 > 30, 'Variable 2 was more than 30.',         'Variables were out of desired ranges.')
The following table lists some sample values and return values:
Var1   
Var2   
RETURN VALUE
21
47
Variable 1 was less than 23.
22
49
Variable 1 was 22!
23
49
Variable 2 was 49!
24
27
Variables were out of desired ranges.
25
50
Variable 2 was more than 30.

0 COMMENTS

We’d like to hear from you!