oracle - Xquery 转换为日期不返回行

标签 oracle xquery

我在 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

最佳答案

您的 XQuery 中有一个拼写错误:该元素名为 <hireDate/> ,但你的轴步数为 hiredate .

关于oracle - Xquery 转换为日期不返回行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22114316/

相关文章:

Java错误: Unable to initialize main class

Oracle ORDS REST - 如何在 PL/SQL 模式下返回处理程序的集合查询?

xml - MarkLogic:在 cts:search 中将字符串转换为路径表达式

sql-server - Oracle Gateway、SQL Server 和 Application Express 的字符集问题

sql-server - ora-00936 缺少表达式选择语句

json - XQuery 3.1 是为高级 JSON 编辑而设计的吗?

xml - 如何在 SQL Server 2008 中合并 2 个 XML 变量

javascript - 在 CSS 和 HTML 中显示 XML

sql - 遍历游标数据并插入记录(如果不存在)

oracle - 我想实现一个触发器以确保新日期不能设置为超出或高于当前日期