Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
由于在另一个重复模式中重复节点,正在提取PL/SQL中的部分XMLType_Sql_Xml_Oracle_Plsql_Xmltype - Fatal编程技术网

由于在另一个重复模式中重复节点,正在提取PL/SQL中的部分XMLType

由于在另一个重复模式中重复节点,正在提取PL/SQL中的部分XMLType,sql,xml,oracle,plsql,xmltype,Sql,Xml,Oracle,Plsql,Xmltype,我有一个XMLType对象,我想将打开时间提取到表中 其中y是上面的XMLType。但这是行不通的,因为它仍然会找到多个item节点。我需要提取标题工作空间2值1、9:00、14:00、3、12:00、16:00的所有元素值。如果我不仅能提取值,而且能提取XMLType的整个部分,这会有所帮助。有什么想法吗? 谢谢,Michal您的目标可以通过以下方式实现: 请注意,我引入了top元素并添加了斜杠作为结束元素,以使XML有效。使用一些@ThinkJet技巧,您的查询可能如下所示 with x a

我有一个XMLType对象,我想将打开时间提取到表中

其中y是上面的XMLType。但这是行不通的,因为它仍然会找到多个item节点。我需要提取标题工作空间2值1、9:00、14:00、3、12:00、16:00的所有元素值。如果我不仅能提取值,而且能提取XMLType的整个部分,这会有所帮助。有什么想法吗?
谢谢,Michal

您的目标可以通过以下方式实现:


请注意,我引入了top元素并添加了斜杠作为结束元素,以使XML有效。

使用一些@ThinkJet技巧,您的查询可能如下所示

with x as (
  select 
    xmltype('
       <workplaces>     
        <workspace>
          <title>workspace1</title>
          <item>
            <day>1</day>
            <openingTime>8:00</openingTime>
            <closingTime>12:00</closingTime>
          </item>
          <item>
            <day>1</day>
            <openingTime>13:00</openingTime>
            <closingTime>18:00</closingTime>
          </item>
        </workspace>
        <workspace>
          <title>workspace2</title>
          <item>
            <day>1</day>
            <openingTime>9:00</openingTime>
            <closingTime>14:00</closingTime>
          </item>
          <item>
            <day>3</day>
            <openingTime>12:00</openingTime>
            <closingTime>16:00</closingTime>
          </item>
        </workspace>
       </workplaces>     
  ') xfield
  from dual
)
SELECT "day", "openingTime", "closingTime"
FROM xmltable('$doc//workspace[title=$workspace_filter]/item'
              passing (select xfield from x) as "doc",
                      ('workspace1') as "workspace_filter"
               columns "openingTime" path '//openingTime',
                       "closingTime" path '//closingTime',
                       "day" path '//day')

我在您和@ThinkJet解决方案之间使用了一些东西,但这需要相当多的时间,大约6分钟。但是我通过web服务读取了相当大的XML文件cca 8 MB,所以也许这不是解决方案的错误当我考虑它时,它一点也不慢,8 MB的6分钟速度非常快
SELECT ExtractValue(Value(p),'workspace/item/day/text()') as day
      ,ExtractValue(Value(p),'workspace/item/openingTime/text()') as open
      ,ExtractValue(Value(p),'workspace/item/closingTime/text()') as close
      FROM TABLE (XMLSequence(Extract(y,'workspace'))) p
      WHERE ExtractValue(Value(p),'/workspace/title/text()') LIKE 'workspace1';
with x as ( -- Just to introduce XML parameter
  select 
    xmltype('
       <workspace_list>     
        <workspace>
          <title>workspace1</title>
          <item>
            <day>1</day>
            <openingTime>8:00</openingTime>
            <closingTime>12:00</closingTime>
          </item>
          <item>
            <day>1</day>
            <openingTime>13:00</openingTime>
            <closingTime>18:00</closingTime>
          </item>
        </workspace>
        <workspace>
          <title>workspace2</title>
          <item>
            <day>1</day>
            <openingTime>9:00</openingTime>
            <closingTime>14:00</closingTime>
          </item>
          <item>
            <day>3</day>
            <openingTime>12:00</openingTime>
            <closingTime>16:00</closingTime>
          </item>
        </workspace>
       </workspace_list>     
  ') xfield
  from dual
)  
select 
  workspace, day, opening_time, closing_time
from
 XMLTable(
   '
     for $i in $doc//workspace[title eq $workspace_filter]
     for $j in $i/item 
     return 
      <wks_item>
        <wks_name>{$i/title/text()}</wks_name> 
        {$j/*}
      </wks_item> 
   '
   passing 
    (select xfield from x) as "doc",
    ('workspace1')         as "workspace_filter"
   columns
   workspace     varchar2(100) path '//wks_name',
   day           varchar2(100) path '//day',
   opening_time  varchar2(100) path '//openingTime',
   closing_time  varchar2(100) path '//closingTime'
 )
with x as (
  select 
    xmltype('
       <workplaces>     
        <workspace>
          <title>workspace1</title>
          <item>
            <day>1</day>
            <openingTime>8:00</openingTime>
            <closingTime>12:00</closingTime>
          </item>
          <item>
            <day>1</day>
            <openingTime>13:00</openingTime>
            <closingTime>18:00</closingTime>
          </item>
        </workspace>
        <workspace>
          <title>workspace2</title>
          <item>
            <day>1</day>
            <openingTime>9:00</openingTime>
            <closingTime>14:00</closingTime>
          </item>
          <item>
            <day>3</day>
            <openingTime>12:00</openingTime>
            <closingTime>16:00</closingTime>
          </item>
        </workspace>
       </workplaces>     
  ') xfield
  from dual
)
SELECT "day", "openingTime", "closingTime"
FROM xmltable('$doc//workspace[title=$workspace_filter]/item'
              passing (select xfield from x) as "doc",
                      ('workspace1') as "workspace_filter"
               columns "openingTime" path '//openingTime',
                       "closingTime" path '//closingTime',
                       "day" path '//day')