XQuery의 문자열 검색
적용 대상:SQL Server
이 항목에서는 XML 문서에서 텍스트를 검색하는 방법을 보여 주는 샘플 쿼리를 제공합니다.
예
A. 제품 카탈로그에서 "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
이전 쿼리 where
에서 FLOWR 식은 식의 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>
참고 항목
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기