CARDINALITY 函数

CARDINALITY 函数返回列表中元素的数量。

语法

CARDINALITY 返回一个整数值,表明 ListExpression 指定的列表中的元素数量。

ListExpression 是返回列表的任何表达式。例如,下列各项全部返回列表:
  • LIST 构造函数
  • 带数组指示符 [] 的字段引用
  • 某些 SELECT 表达式(并非全部返回列表)

此函数通常用于在迭代前确定列表中的字段数量。

示例

-- Determine the number of F1 fields in the message.
-- Note that the [ ] are required
DECLARE CountF1 INT CARDINALITY(OutputRoot.XML.Data.Source.F1[]);
-- Determine the number of fields called F1 with the value 'F12' in the message.
-- Again note that the [ ] are required
DECLARE CountF1F12 INT
  CARDINALITY(SELECT F.* FROM OutputRoot.XML.Data.Source.F1[] AS F
              where F = 'F12');
-- Use the value returned by CARDINALITY to refer to a specific element
-- in a list or array:
-- Array indices start at 1, so this example refers to the third-from-last
-- instance of the Item field
Body.Invoice.Item[CARDINALITY(Body.Invoice.Item[]) - 2].Quantity
相关概念
ESQL 概述
相关任务
正在开发 ESQL
相关参考
EXISTS 函数
SINGULAR 函数
THE 函数
语法图:可用类型
ESQL 列表函数
声明 | 商标 | 下载 | 书库 | 支持 | 反馈
Copyright IBM Corporation 1999, 2006 最后一次更新时间:2006/08/14
ak05530_