我使用Oracle“pivot XML”生成以下格式化的XML,即:
<?xml version="1.0" encoding="UTF-8"?>
<PivotSet>
<item>
<column name="INTERFACE_NO">1</column>
<column name="INTERFACE_NAME_A">abc1</column>
<column name="INTERFACE_L">11</column>
<column name="INTERFACE_R">22</column>
</item>
<item>
<column name="INTERFACE_NO">2</column>
<column name="INTERFACE_NAME_A">abc2</column>
<column name="INTERFACE_L">33</column>
<column name="INTERFACE_R">44</column>
</item>
<item>
<column name="INTERFACE_NO">3</column>
<column name="INTERFACE_NAME_A">abc3</column>
<column name="INTERFACE_L">55</column>
<column name="INTERFACE_R">66</column>
</item>
<item>
<column name="INTERFACE_NO">4</column>
<column name="INTERFACE_NAME_A">abc4</column>
<column name="INTERFACE_L">77</column>
<column name="INTERFACE_R">882</column>
</item>
</PivotSet>
基于上面的XML,使用Oracle SQL(11g)如何提取上面的所有值?
例如,我一直在使用以下内容,即
select
extractvalue(aggregated_interface_no_xml,'/PivotSet/item[2]/column[1]') aa,
extractvalue(aggregated_interface_no_xml,'/PivotSet/item[2]/column[2]') bb,
extractvalue(aggregated_interface_no_xml,'/PivotSet/item[2]/column[3]') cc,
extractvalue(aggregated_interface_no_xml,'/PivotSet/item[2]/column[4]') dd
from t
但这只会返回与INTERFACE_NO 2相关的数据。
我不确定如何针对/PivotSet/item
传递通配符以返回每个项目的XML PivotSet中的所有记录?
答案 0 :(得分:1)
不推荐使用Xmlsequence。 Xmltable是一个很好的干净方法。
.factory('Test', ['$resource', function ($resource) {
return $resource('data.json');
}])
.controller('MyCtrl', ['$scope', 'Test', function($scope, Test) {
Test.get(function (data) {
$scope.myData = data;
});
$scope.myFunction = function() {
var min = $scope.myData.min;
var max = $scope.myData.max;
var diff = max - min;
return diff;
}
}])
答案 1 :(得分:0)
您可以使用xml表执行此操作。像这样:
SELECT EXTRACTVALUE(VALUE(xml_list), '//column[1]') AS interface_no
,EXTRACTVALUE(VALUE(xml_list), '//column[2]') AS interface_name_a
,EXTRACTVALUE(VALUE(xml_list), '//column[3]') AS interface_l
,EXTRACTVALUE(VALUE(xml_list), '//column[4]') AS interface_r
FROM TABLE(XMLSEQUENCE(EXTRACT(XMLType('<?xml version="1.0" encoding="UTF-8"?>
<PivotSet>
<item>
<column name="INTERFACE_NO">1</column>
<column name="INTERFACE_NAME_A">abc1</column>
<column name="INTERFACE_L">11</column>
<column name="INTERFACE_R">22</column>
</item>
<item>
<column name="INTERFACE_NO">2</column>
<column name="INTERFACE_NAME_A">abc2</column>
<column name="INTERFACE_L">33</column>
<column name="INTERFACE_R">44</column>
</item>
<item>
<column name="INTERFACE_NO">3</column>
<column name="INTERFACE_NAME_A">abc3</column>
<column name="INTERFACE_L">55</column>
<column name="INTERFACE_R">66</column>
</item>
<item>
<column name="INTERFACE_NO">4</column>
<column name="INTERFACE_NAME_A">abc4</column>
<column name="INTERFACE_L">77</column>
<column name="INTERFACE_R">882</column>
</item>
</PivotSet>'), 'PivotSet/item'))) xml_list;