XMLTABLE is part of the SQL/XML standard and acts like a table-valued function. It takes an XML value (or XML document) and an XPath/XQuery expression, produces a row for each matching node, and maps XML elements or attributes to relational columns with explicit data types. Because the XML parsing happens inside the database engine, XMLTABLE lets you join or filter XML content with regular SQL, eliminating the need for external parsing. It supports namespace declarations, default values, column-level PATH overrides, and optional ORDINALITY to generate a sequence number per row. Performance depends on XML indexes and the database’s XML storage model. Not all databases implement every feature, so check dialect specifics.
XMLNAMESPACES
(clause) - Declares XML namespaces used in XPath expressionsrow_xpath
(string) - XPath/XQuery that selects the set of XML nodes to turn into rowsPASSING
(keyword) - Supplies one or more XML values to the XPath contextxml_value
(XML) - The XML document or fragment being queriedCOLUMNS
(clause) - Defines the relational projection for each rowcolumn_name
(identifier) - Name of the output columndata_type
(SQL type) - Data type to cast the XML value into (VARCHAR, NUMBER, DATE, etc.)PATH
(string) - Optional XPath for the column, relative to the row nodeDEFAULT
(expression) - Fallback value when the XPath result is emptyORDINALITY
(keyword) - Adds an auto-incrementing column indicating row positionXMLQUERY, XMLNAMESPACES, XQUERY, JSON_TABLE, LATERAL JOIN, CROSS APPLY
SQL:2006 (SQL/XML) and Oracle Database 10g Release 2
Oracle, PostgreSQL, DB2, Teradata, and some columnar engines support it. MySQL and SQLite do not.
No. XMLTABLE is used inline in the FROM clause and behaves like a derived table; no permanent table is created.
Add a column with the FOR ORDINALITY keyword. The column will contain a sequential integer starting at 1.
Yes, but performance relies on XML indexes and streaming capabilities. Always index the XML column or store pre-shredded data for very large documents.