PL/SQL 原始数据类型变量比较
是否可以比较原始数据类型的变量? 我正在使用 XMLDOM.DomNodes,它是一种单独包含一个字段的记录:
TYPE DOMNode IS RECORD (id RAW(12));
所以我有两个节点,那么我可以通过它们的 id 字段来比较它们吗?我尝试了几个示例,乍一看似乎可行:
FUNCTION findParentNode(p_node IN xmldom.domnode) RETURN PLS_INTEGER
AS
nRetVal PLS_INTEGER;
BEGIN
FOR i IN ParentNodes.First .. ParentNodes.Last
LOOP
IF ParentNodes(i).id = p_node.id THEN
nRetVal := i;
EXIT;
END IF;
END LOOP;
RETURN nRetVal;
END;
但 Oracle 文档中的一件事让我担心: 原始数据类似于 VARCHAR2 数据,只是 PL/SQL 不解释原始数据 这是什么意思?如果 pl/sql 不解释 raw,那么它可以比较吗?
Is it possible to compare variables of raw datatypes?
I'm working with XMLDOM.DomNodes, which is records with one field by itself:
TYPE DOMNode IS RECORD (id RAW(12));
So I have two nodes, then could I compare them by their id fields? I tried several samples and at first glance it seems to work:
FUNCTION findParentNode(p_node IN xmldom.domnode) RETURN PLS_INTEGER
AS
nRetVal PLS_INTEGER;
BEGIN
FOR i IN ParentNodes.First .. ParentNodes.Last
LOOP
IF ParentNodes(i).id = p_node.id THEN
nRetVal := i;
EXIT;
END IF;
END LOOP;
RETURN nRetVal;
END;
but one thing in Oracle documentation worries me:
Raw data is like VARCHAR2 data, except that PL/SQL does not interpret raw data
What does it mean? If pl/sql doesn't interpret raw, then could it compare?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您想查看两个 RAW 变量是否具有相同的值,可以使用
=
运算符。当文档指出 RAW 与 VARCHAR2 类似但未解释时,这意味着您可以像 VARCHAR2 一样影响、存储甚至比较 RAW 变量,但二进制值永远不会与字符集匹配。
另一方面,由于数据库和客户端的字符集不匹配,VARCHAR2 变量可以进行转换。
RAW是一串字节而不是一串字符。
You can use the
=
operator if you want to see if two RAW variables have the same values.When the documentation states that RAW is like VARCHAR2, but not interpreted, it means that you can affect, store and even compare RAW variables just like you would VARCHAR2, but the binary value is never matched against a character set.
VARCHAR2 variables, on the other hand, can be converted because of a mismatch between the character sets of the database and the client.
RAW is a string of bytes instead of a string of characters.
我不确定文档的含义,但要比较两个原始数据,我将使用 UTL_RAW.COMPARE 函数。有关详细信息,请参阅此处。
I'm not sure what the documentation means by that but to compare two raws I'd use the
UTL_RAW.COMPARE
function. See here for the details.您必须使用:
Oracle 不会正确比较空/空字符串,因此您必须指定如果它是 null 或空,则赋予它与另一个不同的含义。
You must use:
Oracle does not compare empty/null strings correctly, so you must specify that if it is null or empty, then give it a different meaning than the other.