Aracılığıyla paylaş


concat işlevi (XQuery)

Sıfır veya daha fazla dize bağımsız değişkenler olarak kabul eder ve her birinin bu bağımsız değişken değerleri birleştirilmesiyle oluşturulan bir dize döndürür.

Sözdizimi

fn:concat ($string as xs:string?
           ,$string as xs:string?
           [, ...]) as xs:string

Bağımsız değişkenler

  • $string
    Art arda bağlamak için isteğe bağlı dize.

Açıklamalar

işlev en az iki bağımsız değişken gerektirir.Bağımsız değişken boş bir sıra ise, sıfır uzunluklu dize olarak kabul edilir.

Örnekler

Bu konuda çeşitli içinde depolanan xml örnekleri karşı XQuery örnekler sağlar xml sütunları yazın AdventureWorks2008R2 örnek veritabanı.Bu sütunları genel bakış için bkz: XML veri türü temsili AdventureWorks2008R2 veritabanında.

A.Concat() XQuery kullanarak işlev dizeleri bitiştirmek için

Belirli bir ürün modeline için bu sorgu garanti süresi ve garanti açıklama birleştirilmesiyle oluşturulan bir dize döndürür.Katalog açıklaması belgede, <Warranty> öğesi oluşur <WarrantyPeriod> ve <Description> alt öğeleri.

WITH XMLNAMESPACES (
'https://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription' AS pd,
'https://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelWarrAndMain' AS wm)
SELECT CatalogDescription.query('
    <Product 
        ProductModelID= "{ (/pd:ProductDescription/@ProductModelID)[1] }"
        ProductModelName = "{ sql:column("PD.Name") }" >
        { 
          concat( string((/pd:ProductDescription/pd:Features/wm:Warranty/wm:WarrantyPeriod)[1]), "-",
                  string((/pd:ProductDescription/pd:Features/wm:Warranty/wm:Description)[1])) 
         } 
     </Product>
 ') as Result
FROM Production.ProductModel PD
WHERE  PD.ProductModelID=28;

Önceki sorgudan aşağıdakilere dikkat edin:

  • select yan tümce tümce tümcesinde CatalogDescription olan bir xml türü sütun.Bu nedenle, query() yöntem (xml veri türü), Instructions.query(), kullanılır.XQuery deyim query yöntemni bağımsız olarak belirtilir.

  • Sorgu yürütüldüğü karşı belge ad alanları kullanır.Bu nedenle, ad anahtar sözcüğünü önek için ad alanı tanımlamak üzere kullanılır.Daha fazla bilgi için bkz: XQuery önsöz.

Bu sonucu verir:

<Product ProductModelID="28" ProductModelName="Road-450">1 year-parts and labor</Product>

Önceki sorgu, belirli bir ürün için bilgi alır.Aşağıdaki sorgu xml katalog açıklamaları saklandığı tüm ürünler için aynı bilgileri alır.The exist() method of the xml data type in the WHERE clause returns True if the XML document in the rows has a <ProductDescription> element.

WITH XMLNAMESPACES (
'https://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription' AS pd,
'https://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelWarrAndMain' AS wm)

SELECT CatalogDescription.query('
    <Product 
        ProductModelID= "{ (/pd:ProductDescription/@ProductModelID)[1] }" 
        ProductName = "{ sql:column("PD.Name") }" >
        { 
          concat( string((/pd:ProductDescription/pd:Features/wm:Warranty/wm:WarrantyPeriod)[1]), "-",
                  string((/pd:ProductDescription/pd:Features/wm:Warranty/wm:Description)[1])) 
         } 
     </Product>
 ') as Result
FROM Production.ProductModel PD
WHERE CatalogDescription.exist('//pd:ProductDescription ') = 1

Boole değeri tarafından döndürülen Not exist() yöntem xml türü 1 ile karşılaştırıldığında.

Uygulama kısıtlamaları

Sınırlamalar şunlardır:

  • The concat() function in SQL Server only accepts values of type xs:string.Diğer değerleri xs:dize veya xdt:untypedAtomic için açıkça artığını gerekir.