XMLEXISTS is part of the SQL/XML standard (ISO/IEC 9075-14) and allows relational queries to test the existence of XML nodes directly in SQL statements. It takes an XQuery expression and one or more XML or SQL values to bind to that expression. If the XQuery returns a non-empty sequence, XMLEXISTS returns TRUE; otherwise it returns FALSE. The function is deterministic and side-effect-free. Implementations typically map the Boolean result to their native Boolean type or to 1/0. Key points:- Uses full XQuery 1.0 syntax (or a subset, depending on the database).- PASSING clause binds context items or external variables in the XQuery.- BY REF (default) passes a reference to the XML value; BY VALUE creates an internal copy. BY VALUE can be slower but isolates the query from subsequent changes to the XML.- In most dialects, XMLEXISTS can appear in SELECT, WHERE, HAVING, CHECK constraints, triggers, and views.- NULL handling: if any argument is NULL, the result is NULL in PostgreSQL and SQL Server; Oracle and DB2 treat NULL as an empty sequence, returning FALSE.
xquery_expression
(string) - XQuery 1.0 expression to evaluatevalue_expression
(XML/any) - XML or SQL value(s) bound to the XQuery using the PASSING clauseXMLQUERY, XMLTABLE, XMLSerialize, XPath, XQuery, XML data type
SQL:2006 (ISO/IEC 9075-14) and Oracle Database 10g Release 2
Oracle, PostgreSQL, IBM Db2, SQL Server 2017+, and several others implement XMLEXISTS or an equivalent function.
Yes. You can pass several XML or scalar values and reference them in the XQuery using positional or named variables, depending on the dialect.
XMLEXISTS returns a Boolean indicating node existence, while XMLQUERY returns the actual XML or text result of the XQuery expression.
BY VALUE copies the XML data before evaluation, which can degrade performance on large documents. Use BY REF unless you need isolation from concurrent modifications.