Aracılığıyla paylaş


boş işlev (XQuery)

True ise işlevi değeri $arg boş bir sıra.Aksi durumda, işlev False değerini döndürür.

Sözdizimi

fn:empty($arg as item()*) as xs:boolean

Bağımsız değişkenler

  • $arg
    Öğelerin sırası.Sıra boş ise, işlev doğru verir.Aksi durumda, işlev False değerini döndürür.

Açıklamalar

The fn:exists() function is not supported.Başka bir seçenek olarak, not() işlev kullanılabilir.

Örnekler

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

A.Empty() XQuery kullanarak işlev özniteliği olup olmadığını belirlemek için

Bu sorgu için ürün modeli 7 üretim sürecinde olan tüm iş merkezi konumları döndürür bir MachineHours öznitelik.

SELECT ProductModelID, Instructions.query('
declare namespace AWMI="https://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelManuInstructions";
     for $i in /AWMI:root/AWMI:Location[empty(@MachineHours)]
     return
       <Location
            LocationID="{ ($i/@LocationID) }"
            LaborHrs="{ ($i/@LaborHours) }" >
            { 
              $i/@MachineHours
            }  
       </Location>
') as Result
FROM Production.ProductModel
where ProductModelID=7;

Bu sonucu verir:

ProductModelID Result

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

7 <Location LocationID="30" LaborHrs="1"/>

<Location LocationID="50" LaborHrs="3"/>

<Location LocationID="60" LaborHrs="4"/>

"notfound" biraz değiştirilmiş, aşağıdaki sorgu döndürür MachineHour öznitelik değil:

SELECT ProductModelID, Instructions.query('
declare namespace p14="https://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelManuInstructions";
     for $i in /p14:root/p14:Location
     return
       <Location
            LocationID="{ ($i/@LocationID) }"
            LaborHrs="{ ($i/@LaborHours) }" >
            { 
                 if (empty($i/@MachineHours)) then
                    attribute MachineHours { "NotFound" }
                 else
                    attribute MachineHours { data($i/@MachineHours) }
            }  
       </Location>
') as Result
FROM Production.ProductModel
where ProductModelID=7;

Bu sonucu verir:

ProductModelID Result

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

7

<Location LocationID="10" LaborHrs="2.5" MachineHours="3"/>

<Location LocationID="20" LaborHrs="1.75" MachineHours="2"/>

<Location LocationID="30" LaborHrs="1" MachineHours="NotFound"/>

<Location LocationID="45" LaborHrs="0.5" MachineHours="0.65"/>

<Location LocationID="50" LaborHrs="3" MachineHours="NotFound"/>

<Location LocationID="60" LaborHrs="4" MachineHours="NotFound"/>