문서를 영문으로 보려면 영문 확인란을 선택하세요. 마우스 포인터를 텍스트 위로 이동시켜 팝업 창에서 영문 텍스트를 표시할 수도 있습니다.
|
번역
영문
|
string-length 함수(XQuery)
DECLARE @x xml; SET @x='<ROOT>Hello</ROOT>'; SELECT @x.query('/ROOT[string-length()=5]');
보조 문자(서로게이트 쌍)
1.string-length() XQuery 함수를 사용하여 긴 요약 설명이 포함된 제품 검색
WITH XMLNAMESPACES ('http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription' as pd) SELECT CatalogDescription.query(' <Prod ProductID= "{ /pd:ProductDescription[1]/@ProductModelID }" > <LongSummary SummaryLength = "{string-length(string( (/pd:ProductDescription/pd:Summary)[1] )) }" > { string( (/pd:ProductDescription/pd:Summary)[1] ) } </LongSummary> </Prod> ') as Result FROM Production.ProductModel WHERE CatalogDescription.value('string-length( string( (/pd:ProductDescription/pd:Summary)[1]))', 'decimal') > 200;
WHERE 절의 조건은 XML 문서에 저장된 요약 설명이 200자 이상인 행만 검색합니다. 이 조건에는 value() 메서드(XML 데이터 형식)가 사용됩니다. SELECT 절은 사용자가 원하는 XML만을 생성합니다. 이 절에서는 query() 메서드(XML 데이터 형식)를 사용하여 XML을 생성하고 XML 문서에서 데이터를 검색하기 위해 필요한 XQuery 식을 지정합니다.
Result ------------------- <Prod ProductID="19"> <LongSummary SummaryLength="214">Our top-of-the-line competition mountain bike. Performance-enhancing options include the innovative HL Frame, super-smooth front suspension, and traction for all terrain. </LongSummary> </Prod> ...
2.string-length() XQuery 함수를 사용하여 보증 설명이 짧은 제품 검색
WITH XMLNAMESPACES ( 'http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription' AS pd, 'http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelWarrAndMain' AS wm) SELECT CatalogDescription.query(' for $ProdDesc in /pd:ProductDescription, $pf in $ProdDesc/pd:Features/wm:Warranty where string-length( string(($pf/wm:Description)[1]) ) < 20 return <Prod > { $ProdDesc/@ProductModelID } <ShortFeature FeatureDescLength = "{string-length( string(($pf/wm:Description)[1]) ) }" > { $pf } </ShortFeature> </Prod> ') as Result FROM Production.ProductModel WHERE CatalogDescription.exist('/pd:ProductDescription')=1;
pd 및 wm은 이 쿼리에서 사용되는 네임스페이스 접두사입니다. 이 접두사는 쿼리 중인 문서에 사용되는 동일 네임스페이스를 식별합니다. XQuery는 중첩된 FOR 루프를 지정합니다. <ProductDescription> 요소의 ProductModelID 특성을 검색하기 때문에 외부 FOR 루프는 필수입니다. 20자 미만의 보증 기능 설명이 포함된 제품만 필요하기 때문에 내부 FOR 루프도 필수입니다.
Result ------------------------- <Prod ProductModelID="19"> <ShortFeature FeatureDescLength="15"> <wm:Warranty xmlns:wm="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelWarrAndMain"> <wm:WarrantyPeriod>3 years</wm:WarrantyPeriod> <wm:Description>parts and labor</wm:Description> </wm:Warranty> </ShortFeature> </Prod> ...