With the inline form of Lookup, all of the comparison values are specified as inline parameters within the Lookup instance in the SQL statement. By contrast, the CSV file version of Lookup specifies the location of an external file that contains all of the comparison values.
Other than the manner of specifying lookup values, there are no substantial differences between the two types of Lookup. However, inline Lookup might be preferred over CSV file Lookup if the array of values is not too large, or if it is desirable to avoid an external dependency in the form of a CSV file.
The syntax for an inline LOOKUP predicate appears below:
lookup condition
The conditional expression containing placeholders. Multiple sub-conditions can be connected by the logical AND or OR conjunctions. Parentheses can be used to group sub-conditions for readability and/or to override the logical order of processing.
The placeholders take the form of "%p", where p is an integer ranging from 1 to the total number of values in each row of the data array. The number of distinct placeholders can be less than the total number of values in each array row, which means that one or more columns of values in the array will be ignored when testing the Lookup conditions. For instance, in the expression "col1 > %1 AND col3 = %3 AND col7 < %7", only the 1st, 3rd, and 7th values in each row of the array are used.
The placeholders do not have to appear in sequential order from right to left within the expression. For example, "col1 = %3 OR col2 = %2 OR col3 = %1" is a perfectly valid expression.
Also, the same array value can be used multiple times in the expression, simply by repeating the specific placeholder. For example, we could have this expression: "col1 = %1 AND col2 > %1". This means that the same value will be compared against both col1 and col2.
Note that a comma (
,
) must follow the
lookup condition
parameter.
row of values
A row of values in the "array" that will be inserted into the lookup expression. Each row must have the same number of values, separated by commas, and the datatype at the same position in each row must be compatible.
Currently, there is no way to specify null values. An empty string can be specified using two single quotation marks (
''
).
Each row of values must be contained in parentheses, and separated from the next row by a comma.
Any individual character value can be specified using the hexadecimal format. For example, the uppercase letter "Z" (ASCII hexadecimal code: 5A) can be represented as:
x'5A'
Similarly, the unprintable line feed control character can be specified as:
x'0A'
A full string can also be represented in hexadecimal form by concatenating the ASCII codes for all the characters in the string. For example, the string "Crüe" can be written as:
x'4372FC65'
String concatenation is supported for inline Lookup strings, using the concatenation (
||
) operator.This makes it possible to specify the hexadecimal form only for extended or unprintable characters, instead of for the whole string. For instance, the string "Crüe" can also be written as:
'Cr'||x'FC'||'e'
Note that literal single quotation marks (
'
) can be referenced by escaping the quote; that is, specifying two consecutive single quotation marks (
''
). Alternatively, single quotation marks can be specified using the hexadecimal representation:
x'27'
The following two Lookup strings are therefore equivalent:
'''Drive,'', she said.'
x'27'||'Drive,'||x'27'||' she said.'