dize işlev (XQuery)
Değeri $argbir dizge olarak temsil.
Sözdizimi
fn:string() as xs:string
fn:string($arg as item()?) as xs:string
Bağımsız değişkenler
- $arg
Bir düğüm veya atomik değeri olur.
Açıklamalar
Eğer $argboş sırası ise sıfır uzunluklu dize döndürdü.
Eğer $argbir düğüm işlevi string değeri erişeni kullanılarak elde edilen düğüm dize değerini döndürür. Bu W3C XQuery 1.0 ve XPath 2.0 veri modeli özellikleri tanımlanır.
Eğer $argbir atomik değeri olarak artığını ifade tarafından döndürülen aynı dize işlev verir XS, $arg, aksi belirtilmediği dışında.
Eğer türü $argolan anyURI, URI özel karakterler kaçış olmadan bir dizeye dönüştürülür.
Bu uygulama, fn:string() olmadan bağımsız değişken yalnızca içerik bağımlı yüklemi içeriğinde kullanılabilir. Özellikle, o sadece ayraçlar ([]) içinde kullanılabilir.
Örnekler
Bu konu çeşitli depolanan xml örnekleri karşı XQuery örnekler sağlar xml AdventureWorks veritabanındaki sütunları yazın. Bu sütunlar genel bakış için bkz: DEL - xml Data Type Representation in the AdventureWorks2008R2 Database.
A.Dize işlevini kullanma
Aşağıdaki sorgu alır <Features> alt öğe düğümü <ProductDescription> öğesi.
SELECT CatalogDescription.query('
declare namespace PD="https://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription";
/PD:ProductDescription/PD:Features
')
FROM Production.ProductModel
WHERE ProductModelID=19
SELECT CatalogDescription.query('
declare namespace PD="https://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription";
/PD:ProductDescription/PD:Features
')
FROM Production.ProductModel
WHERE ProductModelID=19
Bu kısmi bir sonucudur:
<PD:Features xmlns:PD="https://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription">
These are the product highlights.
<p1:Warranty xmlns:p1="https://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelWarrAndMain">
<p1:WarrantyPeriod>3 years</p1:WarrantyPeriod>
<p1:Description>parts and labor</p1:Description>
</p1:Warranty>
...
</PD:Features>
<PD:Features xmlns:PD="https://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription">
These are the product highlights.
<p1:Warranty xmlns:p1="https://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelWarrAndMain">
<p1:WarrantyPeriod>3 years</p1:WarrantyPeriod>
<p1:Description>parts and labor</p1:Description>
</p1:Warranty>
...
</PD:Features>
If you specify string() işlevi, belirtilen düğüm dize değerini alır.
SELECT CatalogDescription.query('
declare namespace PD="https://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription";
string(/PD:ProductDescription[1]/PD:Features[1])
')
FROM Production.ProductModel
WHERE ProductModelID=19
SELECT CatalogDescription.query('
declare namespace PD="https://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription";
string(/PD:ProductDescription[1]/PD:Features[1])
')
FROM Production.ProductModel
WHERE ProductModelID=19
Bu kısmi bir sonucudur.
These are the product highlights.
3 yearsparts and labor...
These are the product highlights.
3 yearsparts and labor...
B.Çeşitli düğümlerde dize işlevini kullanma
Aşağıdaki örnek, bir xml örneği bir xml türü değişkeni atandı. Sorguları uygulanması sonucunu göstermek için belirtilen string() çeşitli düğüm.
declare @x xml
set @x = '<?xml version="1.0" encoding="UTF-8" ?>
<!-- This is a comment -->
<root>
<a>10</a>
just text
<b attr="x">20</b>
</root>
'
declare @x xml
set @x = '<?xml version="1.0" encoding="UTF-8" ?>
<!-- This is a comment -->
<root>
<a>10</a>
just text
<b attr="x">20</b>
</root>
'
Aşağıdaki sorgu belge düğümü dize değeri alır. Bu değer, tüm alt metin düğümleri dize değerini bağlayarak oluşturulur.
select @x.query('string(/)')
select @x.query('string(/)')
Sonuç şudur:
This is a comment 10
just text
20
This is a comment 10
just text
20
Işleme yönergesi düğüm dize değerini almak için aşağıdaki sorgu çalışır. Bir metin düğümü içermediğinden boş bir sıra sonucudur.
select @x.query('string(/processing-instruction()[1])')
select @x.query('string(/processing-instruction()[1])')
Aşağıdaki sorgu açıklama düğüm dize değerini alır ve metin düğümü döndürür.
select @x.query('string(/comment()[1])')
select @x.query('string(/comment()[1])')
Sonuç şudur:
This is a comment
This is a comment