Notitie
Voor toegang tot deze pagina is autorisatie vereist. U kunt proberen u aan te melden of mappen te wijzigen.
Voor toegang tot deze pagina is autorisatie vereist. U kunt proberen om mappen te wijzigen.
van toepassing op:SQL Server-
Retourneert Waar als de waarde van $arg een lege reeks is. Anders retourneert de functie False.
Syntaxis
fn:empty($arg as item()*) as xs:boolean
Argumenten
$arg
Een reeks items. Als de reeks leeg is, retourneert de functie Waar. Anders retourneert de functie False.
Opmerkingen
De functie fn:exists() wordt niet ondersteund. Als alternatief kan de functie niet() worden gebruikt.
Voorbeelden
Dit onderwerp bevat XQuery-voorbeelden voor XML-exemplaren die zijn opgeslagen in verschillende xml--typekolommen in de AdventureWorks-database.
Een. De lege() XQuery-functie gebruiken om te bepalen of een kenmerk aanwezig is
In het productieproces voor productmodel 7 retourneert deze query alle werkcentrumlocaties die geen kenmerk MachineHours hebben.
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
Dit is het resultaat:
ProductModelID Result
-------------- ------------------------------------------
7 <Location LocationID="30" LaborHrs="1"/>
<Location LocationID="50" LaborHrs="3"/>
<Location LocationID="60" LaborHrs="4"/>
De volgende, enigszins gewijzigd, query retourneert 'NotFound' als het kenmerk MachineHour niet aanwezig is:
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
Dit is het resultaat:
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"/>
Zie ook
XQuery-functies op basis van het xml-gegevenstype
exist() Method (XML-gegevenstype)