A field reference consists of a correlation name, followed by zero or more path Fields separated by periods (.). The correlation name identifies a well-known starting point in a message tree. The starting point must therefore be either a declared reference variable or one of the predefined start points, for example InputRoot. The path Fields define a path from the start point to the desired field.
InputRoot.XML.Data.Invoicestarts the broker at the location InputRoot (that is, the root of the input message to a Compute node) and then performs a sequence of navigations. First, it navigates from root to the first child field called XML, then to the first child field of the XML field called Data. Finally, the broker navigates to the first child field of the Data field called Invoice. Whenever this field reference occurs in an ESQL program, the invoice field is accessed.
InputRoot.XML."Customer Data".InvoiceIf you need to refer to fields that contain quotation marks, use two pairs of quotation marks around the reference. For example:
Body.Message."""hello"""
Some identifiers are reserved as keywords but, with the exception
of the correlation name, you can use them in field references without the
use of double quotation marks
InputRoot.XML."Customer Data".{'Customer-' || CurrentCustomer}.Invoicein which the invoices are contained in a folder with a name is formed by concatenating the character literal Customer- with the value in CurrentCustomer (which in this example must be a declared variable of type character).
Note that enclosing anything in double quotation marks in ESQL makes it an identifier; enclosing anything in single quotation marks makes it a character literal. You must enclose all character strings (CHARACTER, BLOB, or BIT) in single quotation marks.
For backward compatibility the LAST keyword is still supported, but its use is deprecated. LAST cannot be used as part of an index expression: [LAST] is valid, and is equivalent to [<], but [LAST3] is not valid.
Field [ > ] -- The first field, equivalent to [ 1 ] Field [ > (a + b) * 2 ] Field [ < ] -- The last field, equivalent to [ LAST ] Field [ < 1 ] -- The last field, equivalent to [ LAST ] Field [ < 2 ] -- The last but one field Field [ < (a + b) / 3 ]
In all the preceding cases a name, or namespace, provided by an expression contained in braces ({}) is equivalent to a name provided as an identifier.
By definition, the name of the notarget namespace is the empty string. The empty string can be selected by expressions which evaluate to the empty string, the empty identifier "", or by reference to a namespace constant defined as the empty string.
The use of field references usually implies searching for an existing field. However, if the required field does not exist, as is usually the case for field references that are the targets of SET statements and those in the AS clauses of SELECT functions, it is created.
In the absence of a type specification, the field's type is not Name or NameValue, which effectively indicates that the new field is nameless
.These defaults can be derived from field names, column names or can simply be manufactured sequence names. If the name is an field name, this is effectively a tree copy, and the namespace name is copied as above.
Otherwise, the namespace of the newly-created field is derived by searching the path, that is, the name is be treated as the NameId syntax of a field reference.
InputRoot.XML.Data[1].Invoice InputRoot.XML.Data.Invoice[1]This construct is most commonly used with an index variable, so that a loop steps though all such fields in sequence. For example:
WHILE count < 32 DO SET TOTAL = TOTAL + InputRoot.XML.Data.Invoice[count].Amount; SET COUNT = COUNT + 1 END WHILE;Use this kind of construct with care, because it implies that the broker must count the fields from the beginning each time round the loop. If the repeat count is large, performance will be poor. In such cases, a better alternative is to use a field reference variable.
InputRoot.XML.Data.Invoice -- Selects the first InputRoot.XML.Data.Invoice[1] -- Selects the first InputRoot.XML.Data.Invoice[>] -- Selects the first InputRoot.XML.Data.Invoice[>1] -- Selects the first InputRoot.XML.Data.Invoice[>2] -- Selects the second InputRoot.XML.Data.Invoice[<] -- Selects the fourth InputRoot.XML.Data.Invoice[<1] -- Selects the fourth InputRoot.XML.Data.Invoice[<2] -- Selects the third InputRoot.XML.Data.Invoice[<3] -- Selects the secondAn index clause can also consist of an empty pair of brackets ( [] ). This selects all fields with matching names. Use this construct with functions that expect lists (for example, SELECT or CARDINALITY or in the assignment SET statements) .
Each field of a field reference can contain a type clause. These are denoted by parentheses ( ( ) ), and accept any expression that returns a non-null value of type integer. The presence of a type expression restricts the fields that are selected to those of the matching type. This construct is most commonly used with generic XML, where there are many field types and it is possible for one XML field to contain both attributes and further XML Fields with the same name.
<Item Value = '1234' > <Value>5678</Value> </Item>Here, the XML field Item has two child Fields both called Value". The child Fields can be distinguished by using type clauses: Item.(XML.Attribute)Value to select the attribute, and Item.(XML.field)Value to select the field.
Notices |
Trademarks |
Downloads |
Library |
Support |
Feedback
![]() ![]() |
ak04861_ |