Question

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);
Was it helpful?

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"]';
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top