SINGULAR 函数返回一个 BOOLEAN 值,表明列表是否只包含一个元素。
如果 ListExpression 指定的列表只包含一个元素,SINGULAR 返回 TRUE。如果该列表包含更多或更少元素,SINGULAR 返回 FALSE。
如果只想知道列表是只包含一个元素还是包含某些其他元素,则 SINGULAR 比使用 CARDINALITY 函数(例如,CARDINALITY(ListExpression) = 1)的表达式执行速度更快。
此函数通常用于确定字段是否唯一。
-- Determine whether there is just one F1 field in the message. -- Note that the [ ] are required DECLARE Field1Unique BOOLEAN SINGULAR(OutputRoot.XML.Data.Source.F1[]);
-- Determine whether there is just one field called F1 with the value 'F12' -- in the message. Again note that the [ ] are required DECLARE Field1F12Unique BOOLEAN SINGULAR(SELECT F.* FROM OutputRoot.XML.Data.Source.F1[] AS F where F = 'F12');