Share via


İşlev (XQuery) içerir.

Xs:boolean türünü gösteren bir değeri döndürür olup olmadığını değeri $arg1 içeren bir dize değeri tarafından belirtilen $arg2.

Sözdizimi

fn:contains ($arg1 as xs:string?, $arg2 as xs:string?) as xs:boolean?

Bağımsız değişkenler

  • $arg1
    Dize değeri sınamak için.

  • $arg2
    Aranacak dize.

Açıklamalar

Varsa değeri $arg2 olan bir sıfır uzunluklu dize işlev verir True.Varsa değeri $arg1 sıfır uzunluklu bir dize ve değerini $arg2 olan bir sıfır uzunluklu dize işlev verir False.

Varsa değeri $arg1 veya $arg2 boş sırası bağımsız değişkeni sıfır uzunluklu dize. kabul edilir

Contains() işlev XQuery'nın varsayılan Unicode kod noktası harmanlama dize karşılaştırma için kullanır.

Belirtilen alt dize değeri $arg2 sahip olacak'den küçük veya buna eşit 4000 karakter.If the value specified is greater than 4000 characters, a dynamic error condition occurs and the contains() function returns an empty sequence instead of a Boolean value of True or False.SQL Server does not raise dynamic errors on XQuery expressions.

Büyük küçük durum duyarlı karşılaştırmaları almak için büyük veya küçük harfle Yaz işlevleri kullanılabilir.

Örnekler

This topic provides XQuery examples against XML instances stored in various xml-type columns in the AdventureWorks2008R2 database.Bir bakış bu sütunların her biri için bkz: XML veri türü temsili AdventureWorks2008R2 veritabanında.

A.Belirli bir karakteri aramak için contains() XQuery işlevini kullanmadize

Aşağıdaki sorgu sözcüğü Aerodynamic Özet açıklamalarını içeren ürünleri bulur.ProductID sorgu döndürür ve <Summary> öğesi için bu tür ürünleri.

--The product model description document uses
--namespaces. The WHERE clause uses the exit()
--method of the xml data type. Inside the exit method,
--the XQuery contains()function is used to
--determine whether the <Summary> text contains the word
--Aerodynamic. 

USE AdventureWorks2008R2;
GO
WITH XMLNAMESPACES ('https://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription' AS pd)
SELECT ProductModelID, CatalogDescription.query('
      <Prod>
         { /pd:ProductDescription/@ProductModelID }
         { /pd:ProductDescription/pd:Summary }
      </Prod>
 ') as Result
FROM Production.ProductModel
where CatalogDescription.exist('
   /pd:ProductDescription/pd:Summary//text()
    [contains(., "Aerodynamic")]') = 1;

Sonuçlar

ProductModelID Result

-------------- ---------

28 <Prod ProductModelID="28">

<pd:Summary xmlns:pd=

"https://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription">

<p1:p xmlns:p1="http://www.w3.org/1999/xhtml">

A TRUE multi-sport bike that offers streamlined riding and

a revolutionary design. Aerodynamic design lets you ride with

the pros, and the gearing will conquer hilly roads.</p1:p>

</pd:Summary>

</Prod>