我在Oracle XDB中有一个名为test的表,只有一行。
SQL> select * from test;
SYS_NC_ROWINFO$
---------------------------
<Employee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="">
<location>
<joiningDate id="onsite">
<hireDate>2012-06-18</hireDate>
</joiningDate>
<joiningDate id="offshore">
<hireDate>2011-07-8</hireDate>
</joiningDate>
</location>
</Employee>
经过时间:00:00:00.00
我也有像
这样的索引CREATE INDEX test_xml_index ON test (OBJECT_VALUE)
INDEXTYPE IS XDB.XMLIndex PARAMETERS ('PATH TABLE test_dates_tab');
BEGIN
DBMS_XMLINDEX.registerParameter(
'myprop',
'ADD_GROUP GROUP test_dates
XMLTable test_dates_tab ''/Employee''
XMLNAMESPACES (''http://www.w3.org/2001/XMLSchema-instance'' AS "xsi")
COLUMNS onsite date PATH ''.//*[@id="onsite"]/hireDate/text()''
');
END;
/
为什么我的查询没有返回空值?
SQL> select x.*
2 from test t,
3 xmltable(
4 xmlnamespaces(
5 'http://www.w3.org/2001/XMLSchema-instance' as "xsi"
6 ),
7 'for $d in /Employee/location
8 where $d/joiningDate[@id="onsite"]/hireDate/text() = xs:date("2012-06-18")
9 return $d'
10 passing t.object_value
11 columns
12 hiredate date path 'hireDate'
13 ) as x
14
SQL> /
HIREDATE
--------------------
得到你的帮助Jens
select x.*
from test t,
xmltable(
xmlnamespaces(
'http://www.w3.org/2001/XMLSchema-instance' as "xsi"
),
'for $d in /Employee/location
where $d/joiningDate[@id="onsite"]/hireDate/text() = xs:date("2012-06-18")
return $d'
passing t.object_value
columns
hiredate date path 'joiningDate[@id="onsite"]/hireDate'
) as x
答案 0 :(得分:2)
您的XQuery中存在拼写错误:该元素名为<hireDate/>
,但您的轴步骤为hiredate
。