[英]Error using DBMS_LOB
Below is my query: 以下是我的查询:
SELECT dbms_lob.compare(NVL(original_xmldoc,'Null'),NVL(update_xmldoc,'Null'))
FROM xml_files;
When I execute, I received an error: 执行时,我收到一个错误:
ORA-06553: PLS-306: wrong number or types of arguments in call to 'COMPARE'
06553. 00000 - "PLS-%s: %s"
Is there something wrong with my syntax? 我的语法有问题吗?
regards, 问候,
Nelz Ki 内兹(Nelz Ki)
If your data types are CLOB
then you can do: 如果您的数据类型为CLOB
则可以执行以下操作:
SELECT DBMS_LOB.COMPARE(
NVL( original_xmldoc, Empty_CLOB() ),
NVL( updated_xmldoc, Empty_CLOB() )
)
FROM xml_files;
However, that probably wouldn't generate the error you are seeing so I am assuming that you are using XMLType
datatypes: 但是,这可能不会产生您所看到的错误,因此我假设您使用的是XMLType
数据类型:
SELECT DBMS_LOB.COMPARE(
NVL( original_xmldoc.getClobVal(), Empty_CLOB() ),
NVL( updated_xmldoc.getClobVal(), Empty_CLOB() )
)
FROM xml_files;
(You could use the magic string 'Null'
, as per your example, instead of Empty_CLOB()
but it seems to me more natural to compare against an empty string rather than a made up value - however, you know your data better than us so it might be appropriate the other way round.) (按照您的示例,您可以使用魔术字符串'Null'
代替Empty_CLOB()
但在我看来,与空字符串进行比较而不是与固定值进行比较-但是,您比我们更了解自己的数据因此反过来可能比较合适。)
From your previous questions your columns are XMLType, not CLOB: 在前面的问题中,您的列是XMLType,而不是CLOB:
create table xml_files(original_xmldoc xmltype, update_xmldoc xmltype);
SELECT dbms_lob.compare(NVL(original_xmldoc,'Null'),NVL(update_xmldoc,'Null'))
FROM xml_files;
ORA-06553: PLS-306: wrong number or types of arguments in call to 'COMPARE'
The dbms_lob.compare()
function expects CLOBs (or BLOBs) or something that be implicitly converted to them. dbms_lob.compare()
函数需要CLOB(或BLOB)或隐式转换为它们的东西。 XMLTypes cannot. XMLTypes不能。 So you need to explicitly convert them: 因此,您需要显式转换它们:
SELECT dbms_lob.compare(NVL(x.original_xmldoc.getclobval(),'Null'),
NVL(x.update_xmldoc.getclobval(),'Null'))
FROM xml_files x;
But you're comparing your fixed string value against an XML document and that might get the wrong result, as you're doing linguistic comparison, essentially between the 'N'
of that string and the '<'
of an actual XML document. 但是,您正在将固定的字符串值与XML文档进行比较,这可能会导致错误的结果,因为在进行语言比较时,实际上是在该字符串的'N'
与实际XML文档的'<'
之间进行比较。 As MTO said, it's probably better to use empty_clob()
instead of 'Null'
- with a quick test they get the opposite results. 正如MTO所说,最好使用empty_clob()
而不是'Null'
empty_clob()
通过快速测试,它们会得到相反的结果。 And NLS settings could potentially change the result of the fixed-string version - bad in itself. 而且NLS设置可能会更改固定字符串版本的结果-本身就很糟糕。
Arguably if you're only looking for the result to be zero (the same) or non-zero (different for any reason) then it doesn't matter, but it's still better for it to be correct. 可以说,如果您只希望结果为零(相同)或非零(由于任何原因而不同),那么这无关紧要,但最好还是要正确。 Maybe someone will look at the actual value later and not realise it's wrong. 也许有人稍后会查看实际值,却没有意识到这是错误的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.