Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.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
使用SQL提取XML数据_Sql_Xml_Oracle_Oracle12c_Xmltype - Fatal编程技术网

使用SQL提取XML数据

使用SQL提取XML数据,sql,xml,oracle,oracle12c,xmltype,Sql,Xml,Oracle,Oracle12c,Xmltype,在我的示例中,我希望能够使用Oracle从名为“Arshad Ali”的客户的XML类型中提取特定数据 这是我插入的xml数据: <Customers> <Customer CustomerName="Arshad Ali" CustomerID="C001"> <Orders> <Order OrderDate="2012-07-04T00:00:00" OrderID="10248">

在我的示例中,我希望能够使用Oracle从名为“Arshad Ali”的客户的XML类型中提取特定数据

这是我插入的xml数据:

  <Customers>
    <Customer CustomerName="Arshad Ali" CustomerID="C001">
      <Orders>
        <Order OrderDate="2012-07-04T00:00:00" OrderID="10248">
          <OrderDetail Quantity="5" ProductID="10" />
          <OrderDetail Quantity="12" ProductID="11" />
          <OrderDetail Quantity="10" ProductID="42" />
        </Order>
      </Orders>
      <Address> Address line 1, 2, 3</Address>
    </Customer>
    <Customer CustomerName="Paul Henriot" CustomerID="C002">
      <Orders>
        <Order OrderDate="2011-07-04T00:00:00" OrderID="10245">
          <OrderDetail Quantity="12" ProductID="11" />
          <OrderDetail Quantity="10" ProductID="42" />
        </Order>
      </Orders>
      <Address> Address line 5, 6, 7</Address>
    </Customer>
    <Customer CustomerName="Carlos Gonzlez" CustomerID="C003">
      <Orders>
        <Order OrderDate="2012-08-16T00:00:00" OrderID="10283">
          <OrderDetail Quantity="3" ProductID="72" />
        </Order>
      </Orders>
      <Address> Address line 1, 4, 5</Address>
    </Customer>
  </Customers>
</ROOT>

XML节点的大小写和确切名称很重要:

SELECT extract(OBJECT_VALUE,
  '/ROOT/Customers/Customer[@CustomerName="Arshad Ali"][@CustomerID="C001"]') "customer"
FROM mytable2
WHERE existsnode (OBJECT_VALUE,
  '/ROOT/Customers/Customer[@CustomerName="Arshad Ali"][@CustomerID="C001"]') = 1

如果只想按名称搜索,则仅使用该属性:

SELECT extract(OBJECT_VALUE,
  '/ROOT/Customers/Customer[@CustomerName="Arshad Ali"]') "customer"
FROM mytable2
WHERE existsnode (OBJECT_VALUE,
  '/ROOT/Customers/Customer[@CustomerName="Arshad Ali"]') = 1
但是
extract()
existsnode()
被弃用;改为使用
xmlquery()
xmlexists()

SELECT xmlquery('/ROOT/Customers/Customer[@CustomerName="Arshad Ali"][@CustomerID="C001"]'
  passing object_value
  returning content) "customer"
FROM mytable2
WHERE xmlexists('/ROOT/Customers/Customer[@CustomerName="Arshad Ali"][@CustomerID="C001"]'
  passing object_value)

XML节点的大小写和确切名称很重要:

SELECT extract(OBJECT_VALUE,
  '/ROOT/Customers/Customer[@CustomerName="Arshad Ali"][@CustomerID="C001"]') "customer"
FROM mytable2
WHERE existsnode (OBJECT_VALUE,
  '/ROOT/Customers/Customer[@CustomerName="Arshad Ali"][@CustomerID="C001"]') = 1

如果只想按名称搜索,则仅使用该属性:

SELECT extract(OBJECT_VALUE,
  '/ROOT/Customers/Customer[@CustomerName="Arshad Ali"]') "customer"
FROM mytable2
WHERE existsnode (OBJECT_VALUE,
  '/ROOT/Customers/Customer[@CustomerName="Arshad Ali"]') = 1
但是
extract()
existsnode()
被弃用;改为使用
xmlquery()
xmlexists()

SELECT xmlquery('/ROOT/Customers/Customer[@CustomerName="Arshad Ali"][@CustomerID="C001"]'
  passing object_value
  returning content) "customer"
FROM mytable2
WHERE xmlexists('/ROOT/Customers/Customer[@CustomerName="Arshad Ali"][@CustomerID="C001"]'
  passing object_value)