xquery version「1.0」;這段代碼有什麼問題(xquery)
聲明函數CON($ S1爲XS:anyAtomicType,$ S2作爲XS:anyAtomicType),爲的xs:串 {
返回的concat($ S1,$ S2) };
將變量$ str1聲明爲xs:string:=「samah」; 將變量$ str2聲明爲xs:string:=「sama」; 聲明變量$ comstring:= con($ str1,$ str2); {$ comstring}
xquery version「1.0」;這段代碼有什麼問題(xquery)
聲明函數CON($ S1爲XS:anyAtomicType,$ S2作爲XS:anyAtomicType),爲的xs:串 {
返回的concat($ S1,$ S2) };
將變量$ str1聲明爲xs:string:=「samah」; 將變量$ str2聲明爲xs:string:=「sama」; 聲明變量$ comstring:= con($ str1,$ str2); {$ comstring}
您的查詢語法錯誤。 return
僅在for
,let
,where
或order by
子句之後有效。刪除字return
。
其次,{
和}
只在節點內容內有效,所以應該刪除。
最終函數和變量不能在XQuery函數名稱空間中聲明,因此這些函數和變量必須在另一個名稱空間中聲明。
編譯器錯誤應該告訴你這一切嗎?
declare namespace test = "http://www.example.org/test";
declare function test:con($s1 as xs:anyAtomicType, $s2 as xs:anyAtomicType) as xs:string
{
concat($s1, $s2)
};
declare variable $test:str1 as xs:string:="samah";
declare variable $test:str2 as xs:string:="sama";
declare variable $test:comstring:=test:con($test:str1 ,$test:str2);
$test:comstring
這工作太:
xquery version "1.0";
declare namespace local = "local";
declare variable $str1 as xs:string:="samah";
declare variable $str2 as xs:string:="sama";
declare variable $comstring := local:con($str1 ,$str2);
declare function local:con($s1 as xs:anyAtomicType, $s2 as xs:anyAtomicType) as xs:string
{
concat($s1, $s2)
};
$comstring