EXISTS 関数は、リストに 1 つ以上のエレメントが含まれているかどうか (つまり、リストがあるかどうか) を示すブール値を戻します。
ListExpression で指定されたリストに 1 つ以上のエレメントが含まれている場合、EXISTS は TRUE を戻します。リストにエレメントが含まれていない場合は、EXISTS は FALSE を戻します。
リストにエレメントが含まれているかどうかのみ知りたい場合は、CARDINALITY 関数に関する式 (CARDINALITY(ListExpression) <> 0 など) よりも、EXISTS の方が速く実行できます。
この関数の一般的な使用法としては、フィールドがあるかどうかを判別する場合があります。
-- 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');