[英]MYSQL EXTRACTVALUE with “<” Less Than Operator returns NULL?
I am using MYSQL with the EXTRACTVALUE command, and the below code returns NULL when using the "<" Less Than Operator. 我将MYSQL与EXTRACTVALUE命令一起使用,并且当使用“ <”小于运算符时,以下代码返回NULL。 But the ">" Greater Than Operator works as intended.
但是,“大于运算符”可以按预期工作。 Why?
为什么?
select EXTRACTVALUE('<TrackerQuery>
<Column>*</Column>
<View> view_sms_speqs</View>
<Filters>
<Filter>
<FilterColumn>DateTested</FilterColumn>
<FilterOperator><</FilterOperator>
<FilterValue>2019-04-18</FilterValue>
</Filter>
</Filters>
</TrackerQuery>', CONCAT('//TrackerQuery//Filters//Filter[', 1, ']//FilterOperator'));
The problem is that the content <tag><</tag>
is not valid, resulting in NULL
being returned. 问题是内容
<tag><</tag>
无效,导致返回NULL
。 This is mentioned in the documentation for EXTRACTVALUE
: EXTRACTVALUE
的文档中提到了这EXTRACTVALUE
:
NULL
is returned ifxml_frag
contains elements which are not properly nested or closed, and a warning is generated, as shown in this example: [...]如果
xml_frag
包含未正确嵌套或关闭的元素,并且生成警告,则返回NULL
,如以下示例所示:[...]
You will see in the following example that there was an error/warning when you use <
as a content because it looks like it is the start of a new XML element. 在以下示例中,您将
<
用作内容时会出现错误/警告,因为它看起来像是新XML元素的开始。
mysql> SELECT EXTRACTVALUE('<abc><def><</def></abc>', '//abc//def');
+-------------------------------------------------------+
| EXTRACTVALUE('<abc><def><</def></abc>', '//abc//def') |
+-------------------------------------------------------+
| NULL |
+-------------------------------------------------------+
1 row in set, 1 warning (0.00 sec)
mysql> SHOW WARNINGS;
+---------+------+-------------------------------------------------------------------------------------------+
| Level | Code | Message |
+---------+------+-------------------------------------------------------------------------------------------+
| Warning | 1525 | Incorrect XML value: 'parse error at line 1 pos 13: '<' unexpected (ident or '/' wanted)' |
+---------+------+-------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
Interesting enough, the value <
有趣的是,值
<
is not working as it should. 无法正常工作。
mysql> SELECT EXTRACTVALUE('<abc><def><</def></abc>', '//abc//def');
+----------------------------------------------------------+
| EXTRACTVALUE('<abc><def><</def></abc>', '//abc//def') |
+----------------------------------------------------------+
| < |
+----------------------------------------------------------+
1 row in set (0.00 sec)
But when you put it in a CDATA block, you will get the correct value. 但是,当您将其放在CDATA块中时,您将获得正确的值。
mysql> SELECT EXTRACTVALUE('<abc><def><![CDATA[<]]></def></abc>', '//abc//def');
+-------------------------------------------------------------------+
| EXTRACTVALUE('<abc><def><![CDATA[<]]></def></abc>', '//abc//def') |
+-------------------------------------------------------------------+
| < |
+-------------------------------------------------------------------+
1 row in set (0.00 sec)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.