Oracle Clob拥有复杂的XML.如何使用Xquery选择特定数据 [英] Oracle Clob holds complex XML; how to select specific data with Xquery

查看:79
本文介绍了Oracle Clob拥有复杂的XML.如何使用Xquery选择特定数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从存储在商业应用程序的CLOB字段中的复杂XML数据集中提取特定数据.我无法更改XML格式(命名空间等),也无法将CLOB更改为XMLType.

I'm trying to extract specific data from a complex XML data set stored in a CLOB field in a commercial app. I cannot change the XML format (namespace, etc), I cannot change the CLOB to XMLType.

xml数据如下:

<?xml version="1.0" encoding="utf-8"?>
<Calculation>
  <ProcessUnitModelScenario Id="1265319" EntityId="10030" EntityName="Chaco Plant" ProcessUnitId="10225" ProcessUnitName="Turbine - Unit 37" EmissionModelId="10000" EmissionModelName="Emissions" ScenarioId="10053" ScenarioName="GHG_Comb_Run_Time" EffectiveDate="1/1/2012 12:00:00 AM" EndDate="2/1/2012 12:00:00 AM" ActiveDate="1/1/2008 12:00:00 AM" ProductionUnitId="10031" ProductionUnitName="Default Production Unit - Month" ProductionScheduleId="13541" OperatingPercentage="100" LinkLevel="1">
    <EmissionModel Id="10935" EffectiveDate="1/1/2012 12:00:00 AM" EndDate="2/1/2012 12:00:00 AM">
      <EmissionModelMaterial Id="13250" OutputType="Air Emissions" OutputTypeId="1" Media="Vapor" MediaName="Air" MaterialId="83" EquationId="10096" EquationName="GHG Combustion: Run time" EquationUnit="lb/hr" EquationUnitName="lb/hr" EquationBaseUnit="lb/hr" EquationBaseUnitName="lb/hr" SpeciationOption="StandardSpeciation" SpeciationOptionName="Standard Speciation" UseComponentVaporPressureMethods="False" VaporPressureOptionName="Material's vapor pressure methods">
        <Material Id="83" Name="Methane" EffectiveId="10082" EffectiveDate="1/1/1990 12:00:00 AM" ComponentBasis="Vapor" MolecularWeight="16.043" LiquidDensity="1.34687732957939" VaporPressureMethod="Riedels" RiedelA="39.205" RiedelB="-1324.4" RiedelC="-3.4366" RiedelD="3.1E-05" RiedelE="2" UseDefinedComposition="False">
          <CalculationPeriod StartDate="1/1/2012 12:00:00 AM" EndDate="2/1/2012 12:00:00 AM">
            <EquationVariable Id="11079" Name="HeatRating" Order="10" BaseUnit="BTU/sec" EquationUnit="MMBtu/hr" Type="System" TypeName="System Variable" SystemCalculationType="ProcessUnitProperty" SystemCalculationName="Process Unit Property" SystemParameterProcessPropertyId="10005" SystemParameterModelOutputTypeId="1" TimeDependent="False" Value="116" EnteredValue="116" EnteredUnit="MMBtu/hr" />
            <EquationVariable Id="11077" Name="GHGEF" Order="20" BaseUnit="lb/BTU" EquationUnit="kg/MMBTU" Type="GlobalEmissionFactor" TypeName="Global Emission Factor" TimeDependent="True" Value="0.001" EnteredValue="0.001" EnteredUnit="kg/MMBTU" />
            <EquationVariable Id="11078" Name="RunHrs" Order="30" BaseUnit="hr" Type="Parameter" TypeName="Parameter" ParameterLevel="ProcessUnit" ParameterLevelName="Process Unit" ParameterId="10044" ParameterName="RunHrs - " TimeDependent="True" Value="612" EnteredValue="612" EnteredUnit="hr" />
            <EquationVariable Id="11080" Name="kgtolb" Order="40" BaseUnit="lb" Type="GlobalConstant" TypeName="Global Constant" GlobalConstantId="10007" TimeDependent="False" Value="2.20462" />
            <EquationVariable Id="11081" Name="OpHrs" Order="45" BaseUnit="hr" EquationUnit="hr" Type="System" TypeName="System Variable" SystemCalculationType="OperatingHours" SystemCalculationName="Operating Hours" TimeDependent="True" Value="744" />
            <EquationVariable Id="11082" Name="EmissionRate" Order="46" BaseUnit="lb/hr" Type="FinalResult" TypeName="Final Expression" Formula="(HeatRating*GHGEF)*RunHrs*kgtolb/OpHrs" TimeDependent="True" Value="0.210363418064516" />
            <Emission EffectiveDate="1/1/2012 12:00:00 AM" EndDate="2/1/2012 12:00:00 AM" BaseUnit="lb/hr" BaseUnitName="lb/hr" EmissionAmount="0.210363418064516" Unit="lb/hr" UnitName="lb/hr" ResultValue="0.210363418064516" LinkType="Unabated" LinkTypeName="" OperatingHours="744" EmissionMass="156.51038304" EmissionMassUnit="lb" MaterialId="83" EffectiveMaterialId="10082" MaterialName="Methane" MaterialEffectiveDate="1/1/1990 12:00:00 AM" />
          </CalculationPeriod>
        </Material>
        <Material  etc...>
        </Material>
      </EmissionModelMaterial>
      <EmissionModelMaterial  etc...>
      </EmissionModelMaterial>
    </EmissionModel> 
    <EmissionModel  etc...> 
    </EmissionModel> 
  <ProcessUnitModelScenario  etc...>
  </ProcessUnitModelScenario>
</Calculation>

我需要从[ProcessUnitModelScenario/@ ProcessUnitId],[ProcessUnitModelScenario/@ ScenarioId]和[Material/@ Id]的指定组合的元素中返回某些属性值.

My need is to return certain attribute values from the elements for specified combination of [ProcessUnitModelScenario/@ProcessUnitId], [ProcessUnitModelScenario/@ScenarioId], and [Material/@Id].

XML数据保存在Air_Calc_Log表Verbose_Xml CLOB字段中.

The XML data is kept in the Air_Calc_Log table Verbose_Xml CLOB field.

在我的PL/SQL中,我(使用?)使用以下选择:

In my PL/SQL I am (mis?)using the follow select:

 SELECT 
  XMLType(l.verbose_xml).extract(
  'for $scen in  /Calculation/ProcessUnitModelScenario
  where ($scen/@ScenarioId="10053")
  return $scen/* ')
      FROM air_calc_log l
   WHERE l.vld_site_id = 10030 -- pVldSite
       AND l.start_date = To_Date('01/01/2012','mm/dd/yyyy')  -- pStartDate
       AND  l.End_Date = To_Date('04/01/2012','mm/dd/yyyy')

我使用FLOWR语法的XQuery/XPath的任何组合我总是会收到以下错误消息:

Whatever combination of XQuery/XPath using FLOWR syntax I use I always get the following error message:

ORA-31011: XML parsing failed
ORA-19202: Error occurred in XML processing
LPX-00601: Invalid token in: 'for $scen in  /Calculation/ProcessUnitModelScenario
  where ($scen/@ScenarioId="10053")
  return $scen/* '
ORA-06512: at "SYS.XMLTYPE", line 111

有人可以帮我指出我在做什么吗?

Can someone help point out what I'm doing wrong?

推荐答案

尝试如下:

SELECT 
  XMLType(l.verbose_xml).extract(
  '/Calculation/ProcessUnitModelScenario[@ScenarioId="10053"]')
      FROM air_calc_log l
WHERE l.vld_site_id = 10030 -- pVldSite
       AND l.start_date = To_Date('01/01/2012','mm/dd/yyyy')  -- pStartDate
       AND  l.End_Date = To_Date('04/01/2012','mm/dd/yyyy')

此处是一个小提琴(请注意,我必须将XML更改为设为well-formed)

Here is a fiddle (Note that I had to change your XML to make it well-formed)

这篇关于Oracle Clob拥有复杂的XML.如何使用Xquery选择特定数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆