这段代码有什么问题(xquery)

时间:2010-02-08 12:37:18

标签: xquery

xquery版本“1.0”;

将函数con($ s1 as xs:anyAtomicType,$ s2 as xs:anyAtomicType)声明为xs:string {
    return concat($ s1,$ s2) };

将变量$ str1声明为xs:string:=“samah”; 将变量$ str2声明为xs:string:=“sama”; 声明变量$ comstring:= con($ str1,$ str2); {$ comstring}

2 个答案:

答案 0 :(得分:1)

这也有效:

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 

答案 1 :(得分:0)

您的查询语法错误。 return仅在forletwhereorder 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