做DB2的开发过程中,有一些问题总是容易重现,因为没有及时记录解决办法,经常需要重新将问题分析一遍,所以有必要开贴备忘。
====================================================================================
1 检索数据库时遇到错误:
Native Error Code = -99999
[IBM][CLI Driver] CLI0125E Function sequence error. SQLSTATE=HY010]
原因:
SQL语句执行后,没有得到检索结果,此时调用SQLFetch接口由于取不到内容而出现上述错误。
出现上述问题的代码如下:
snprintf(query,1024*1024,
"declare default element namespace /"http://www.neusoft.com/nsr/mcml/" "
"declare namespace hd=/"http://www.neusoft.com/nsr/mcml/head/"; "
"declare namespace pi=/"http://www.neusoft.com/nsr/mcml/patient_information/"; "
"declare namespace ce=/"http://www.neusoft.com/nsr/mcml/clinical_examination/"; "
"declare namespace ae=/"http://www.neusoft.com/nsr/mcml/auxiliary_examination/"; "
"select id,xmlquery( ... ... )from casedoc;"
);
这段代码中,名字空间声明的位置不对,应该在xmlquery函数内声明,正确的书写方式如下:
snprintf(query,1024*1024,
"select id,xmlquery( "declare default element namespace /"http://www.neusoft.com/nsr/mcml/" "
"declare namespace hd=/"http://www.neusoft.com/nsr/mcml/head/"; "
"declare namespace pi=/"http://www.neusoft.com/nsr/mcml/patient_information/"; "
"declare namespace ce=/"http://www.neusoft.com/nsr/mcml/clinical_examination/"; "
"declare namespace ae=/"http://www.neusoft.com/nsr/mcml/auxiliary_examination/"; "
... ...
)from casedoc;"
);
2 XQuery的text()函数
"for $case in $d/mcml "
"let $sex := $case/hd:head/text() "
在上面的XQuery语句中若hd:head有嵌入的结点,则text函数返回空值,简单说来,text函数只对简单的包含文本的结点有效。
3 执行db2stop出错:
SQL1025N The database manager was not stopped because databases are still active.
可以改用db2stop force命令强制关闭数据库。