Search code examples
xmlxpathoracle11gxqueryxmltype

How to check for text node of an element in xmltype oracle


Using the following query,

SELECT *
  FROM sampletable
  WHERE XMLExists('/books/book[@max="30"]' passing XMLCOLUMN);

But I want to know , how to check for the plain text content of an element, like

SELECT *
  FROM sampletable
  WHERE XMLExists('/books/book="Content"' passing XMLCOLUMN);

Solution

  • To check if there is a book node where the text node equals Content (from XPath terms it would return all book nodes), do:

    SELECT *
      FROM sampletable
      WHERE XMLExists('/books/book[.="Content"]';
    

    To check if there are books nodes where the child node equals Content (from XPath terms it would return all books nodes), do:

    SELECT *
      FROM sampletable
      WHERE XMLExists('/books[book="Content"]';