EXISTS 函数返回一个 BOOLEAN 值,表明列表是否至少包含一个元素(即,列表是否存在)。
如果 ListExpression 指定的列表包含一个或多个元素,EXISTS 返回 TRUE。如果该列表不包含任何元素,EXISTS 返回 FALSE。
如果只想知道列表是否包含元素,则 EXISTS 比使用 CARDINALITY 函数(例如,CARDINALITY(ListExpression ) <> 0)的表达式执行速度更快。
此函数通常用于确定字段是否存在。
-- Determine whether the F1 array exists in the message. Note that the [ ] -- are required DECLARE Field1Exists BOOLEAN EXISTS(OutputRoot.XML.Data.Source.F1[]);
-- Determine whether the F1 array contains an element with the value 'F12'. -- Again note that the [ ] are required DECLARE Field1F12Exists BOOLEAN EXISTS(SELECT F.* FROM OutputRoot.XML.Data.Source.F1[] AS F where F = 'F12');