以下是我的职责,
create or replace
FUNCTION checkXML
(idx in number , tblname in varchar2)
return xmltype
is
required_xml XMLTYPE;
saved_hash_value raw(50);
current_hash_value raw(50);
xml_not_equal EXCEPTION;
begin
execute immediate 'select checkfield , my_hash(extract(xmlcol,'/')) , xmlcol into saved_hash_value ,
current_hash_value , required_xml from ' || tblname || ' where indexid =' || idx ;
if saved_hash_value = current_hash_value then
return required_xml;
else
RAISE xml_not_equal;
end if;
end;
我想知道哪里出了问题。
正在接收的错误消息是,
ORA-06502: PL/SQL: numeric or value error: character to number conversion error
ORA-06512: at "SYSTEM.CHECKXML", line 11
06502. 00000 - "PL/SQL: numeric or value error%s"
*Cause:
*Action:
您在SQL语句中未转义单引号,因此斜杠/
被解释为除号,而不是字符串的一部分。您需要添加转义符:
my_hash(extract(xmlcol, ''/''))
您还应该idx
真正使用绑定变量,而into
对于动态SQL来说,您的位置是错误的:
execute immediate 'select checkfield , my_hash(extract(xmlcol, ''/'')) ,
xmlcol from ' || tblname || ' where indexed = :idx'
into saved_hash_value , current_hash_value , required_xml
using idx;
同样不确定您要尝试实现的异常。您已经在本地声明它,然后尝试提高它,但是我认为这只会生成未处理的用户定义的异常错误。您可能只想使用自己的错误号和消息引发应用程序错误,例如:
...
if saved_hash_value != current_hash_value then
raise_application_error(-20001, 'XML hash is not correct');
end if;
return required_xml;
end;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句