last 함수(XQuery)

현재 처리 중인 시퀀스의 항목 수를 반환합니다. 특히 시퀀스에서 마지막 항목의 정수 인덱스를 반환합니다. 시퀀스의 첫 번째 항목에는 인덱스 값 1이 있습니다.

구문

fn:last() as xs:integer

주의

SQL Server에서 **fn:last()**는 상황별 조건자 컨텍스트에서만 사용할 수 있습니다. 특히 사용 시 대괄호([ ])로 묶어야 합니다.

이 항목에서는 AdventureWorks 데이터베이스의 다양한 xml 유형 열에 저장된 XML 인스턴스에 대한 XQuery 예를 제공합니다. 이러한 각 열에 대한 개요는 AdventureWorks 데이터베이스의 xml 데이터 형식 표시를 참조하십시오.

1. last() XQuery 함수를 사용하여 마지막 두 제조 단계 검색

다음 쿼리는 특정 제품 모델의 마지막 두 제조 단계를 검색합니다. last() 함수에서 반환한 값 즉, 제조 단계 수는 이 쿼리에서 마지막 두 제조 단계를 검색하는 데 사용됩니다.

SELECT ProductModelID, Instructions.query(' 
declare namespace AWMI="https://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelManuInstructions";
  <LastTwoManuSteps>
   <Last-1Step> 
     { (/AWMI:root/AWMI:Location)[1]/AWMI:step[(last()-1)]/text() }
   </Last-1Step>
   <LastStep> 
     { (/AWMI:root/AWMI:Location)[1]/AWMI:step[last()]/text() }
   </LastStep>
  </LastTwoManuSteps>
') as Result
FROM Production.ProductModel
WHERE ProductModelID=7

위의 쿼리에서 //AWMI:root//AWMI:Location)[1]/AWMI:step[last()]last() 함수는 제조 단계 수를 반환합니다. 이 값은 업무 센터 위치에서 마지막 제조 단계를 검색하는 데 사용됩니다.

다음은 결과입니다.

ProductModelID Result  
-------------- -------------------------------------
7      <LastTwoManuSteps>
         <Last-1Step>
            When finished, inspect the forms for defects per 
            Inspection Specification .
         </Last-1Step>
         <LastStep>Remove the frames from the tool and place them 
            in the Completed or Rejected bin as appropriate.
         </LastStep>
       </LastTwoManuSteps>

참고 항목

참조

xml 데이터 형식에 대한 XQuery 함수

도움말 및 정보

SQL Server 2005 지원 받기