XQuery 中的字串搜尋
適用於:SQL Server
本主題提供範例查詢,示範如何在 XML 檔中搜尋文字。
範例
A. 尋找在產品目錄中包含「維護」一詞的功能描述
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 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應