Sekanslardaki İşlevler - boş

Şunlar için geçerlidir: SQL Server

$arg'nin değeri boş bir dizis ise True döner. Aksi takdirde, fonksiyon Yanlış döndürür.

Syntax

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

Arguments

$arg
Bir dizi eşya. Eğer dizi boşsa, fonksiyon Doğru döner. Aksi takdirde, fonksiyon Yanlış döndürür.

Remarks

fn:exists() fonksiyonu desteklenmemektedir. Alternatif olarak, not() fonksiyonu kullanılabilir.

Examples

Bu konu, AdventureWorks veritabanındaki çeşitli xml türü sütunlarında depolanan XML örneklerine karşı XQuery örnekleri sağlar.

A. Bir özniteliğin var olup olmadığını belirlemek için boş() XQuery fonksiyonu kullanılarak

Ürün Modeli 7 için üretim sürecinde, bu sorgu MachineHours özniteliği olmayan tüm iş merkezi konumlarını döndürür.

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  

Sonuç şu şekildedir:

ProductModelID      Result          
-------------- ------------------------------------------  
7              <Location LocationID="30" LaborHrs="1"/>  
               <Location LocationID="50" LaborHrs="3"/>  
               <Location LocationID="60" LaborHrs="4"/>  

Aşağıdaki, biraz değiştirilmiş sorgu, MachineHour özniteliği yoksa "NotFound" döner:

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  

Sonuç şu şekildedir:

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"/>