The existsnode() XML function

Determines whether the XPath evaluation results in at least one XML element.

Purpose

Determines whether traversal of an XML document using a specified path results in any nodes. Returns 1 if one or more nodes are found; otherwise, returns 0.

The existsnode() syntax

existsnode(xml_document ,xpath_expression)

Parameters

xml_document
The XML document or fragment to evaluate. The document can be of type LVARCHAR or CLOB.
xpath_expression
The XPATH expression to search for XML nodes.

Specify an absolute XPath_string with an initial slash. Omit the initial slash to indicate a path relative to the root node. If no match is found, these functions return an empty string.

Example 1

This example query returns a list of warehouse IDs and names for every warehouse that has an associated dock.
SELECT warehouse_id, warehouse_name
FROM warehouses
WHERE existsnode(warehouse_spec, '/Warehouse/Docks') = 1;