XQuery에서 문자열 검색

이 항목에서는 XML 문서에서 텍스트를 검색하는 방법을 보여 주는 예제 쿼리를 제공합니다.

1.제품 카탈로그에서 "maintenance"라는 단어가 포함된 기능 설명 찾기

SELECT CatalogDescription.query('
     declare namespace p1="https://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription";
    for $f in /p1:ProductDescription/p1:Features/*
     where contains(string($f), "maintenance")
     return
           $f ') as Result
FROM Production.ProductModel
WHERE ProductModelID=19

위의 쿼리에서 FLOWR 식의 where는 for 식의 결과를 필터링하고 contains() 조건을 만족하는 요소만 반환합니다.

다음은 결과입니다.

<p1:Maintenance   
      xmlns:p1="https://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelWarrAndMain">
 <p1:NoOfYears>10</p1:NoOfYears>
 <p1:Description>maintenance contact available through your 
               dealer or any AdventureWorks retail store.</p1:Description>
</p1:Maintenance>

참고 항목

개념

XML 데이터(SQL Server)

관련 자료

XQuery 언어 참조(SQL Server)