我有一个查询如下我需要获取一个列及其值 防爆。第一个值是XML中的AR_GROUP_EMAIL_ID。
我无法确定xpath表达式应该是什么。
select a.* from (select prf_code_xml from myxmltab ) xmltab
, XMLTable(
'/PivotSet'
passing xmltab.prf_code_xml
columns
prf_Code varchar2(20) path '/PivotSet/item/column[1]'
) a
XML:
<PivotSet>
<item>
<column name="PRF_CODE">AR_GROUP_EMAIL_ID</column>
<column name="COUNT(PRF_CODE)">1</column>
</item>
<item>
<column name="PRF_CODE">AUTO_ASN_RECEIVE</column>
<column name="COUNT(PRF_CODE)">1</column>
</item>
<item>
<column name="PRF_CODE">AUTO_EMAIL_PREF</column>
<column name="COUNT(PRF_CODE)">1</column>
</item>
<item>
<column name="PRF_CODE">AUTO_INVOICE_PREF</column>
<column name="COUNT(PRF_CODE)">1</column>
</item>
<item>
<column name="PRF_CODE">BOLT_GL_ENABLED</column>
<column name="COUNT(PRF_CODE)">1</column>
</item>
<item>
<column name="PRF_CODE">CALC_AUTO_FREIGHT</column>
<column name="COUNT(PRF_CODE)">1</column>
</item>
<item>
<column name="PRF_CODE">CHECK_PO_VENDOR</column>
<column name="COUNT(PRF_CODE)">1</column>
</item>
<item>
<column name="PRF_CODE">DISTR_SYNC</column>
<column name="COUNT(PRF_CODE)">1</column>
</item>
<item>
<column name="PRF_CODE">ENG_VAL</column>
<column name="COUNT(PRF_CODE)">1</column>
</item>
<item>
<column name="PRF_CODE">FA-ENABLED</column>
<column name="COUNT(PRF_CODE)">1</column>
</item>
<item>
<column name="PRF_CODE">FA_CREATE_USER</column>
<column name="COUNT(PRF_CODE)">1</column>
</item>
<item>
<column name="PRF_CODE">FA_DELAY_TIME</column>
<column name="COUNT(PRF_CODE)">1</column>
</item>
<item>
<column name="PRF_CODE">FREIGHT_ON_BO</column>
<column name="COUNT(PRF_CODE)">1</column>
</item>
<item>
<column name="PRF_CODE">IQA-RA_ENABLED</column>
<column name="COUNT(PRF_CODE)">1</column>
</item>
<item>
<column name="PRF_CODE">IQA_SENDER</column>
<column name="COUNT(PRF_CODE)">1</column>
</item>
<item>
<column name="PRF_CODE">IQA_TARGET</column>
<column name="COUNT(PRF_CODE)">1</column>
</item>
<item>
<column name="PRF_CODE">IQA_WAIT_TIME</column>
<column name="COUNT(PRF_CODE)">1</column>
</item>
<item>
<column name="PRF_CODE">ONESOURCE_ENABLED</column>
<column name="COUNT(PRF_CODE)">1</column>
</item>
<item>
<column name="PRF_CODE">ORDER_UPDATE</column>
<column name="COUNT(PRF_CODE)">1</column>
</item>
<item>
<column name="PRF_CODE">PO_SHIP_VIA_LOV_CHECK</column>
<column name="COUNT(PRF_CODE)">1</column>
</item>
<item>
<column name="PRF_CODE">PRODWISE_SUGG_ORDERS</column>
<column name="COUNT(PRF_CODE)">1</column>
</item>
<item>
<column name="PRF_CODE">QSSM_ASSET</column>
<column name="COUNT(PRF_CODE)">1</column>
</item>
<item>
<column name="PRF_CODE">QSSM_CONTACT</column>
<column name="COUNT(PRF_CODE)">1</column>
</item>
<item>
<column name="PRF_CODE">QSSM_CUST_SITE</column>
<column name="COUNT(PRF_CODE)">1</column>
</item>
<item>
<column name="PRF_CODE">QSSM_RESP_TIMEOUT</column>
<column name="COUNT(PRF_CODE)">1</column>
</item>
<item>
<column name="PRF_CODE">QSSM_SENDER_ID</column>
<column name="COUNT(PRF_CODE)">1</column>
</item>
<item>
<column name="PRF_CODE">QSSM_SERV_WO</column>
<column name="COUNT(PRF_CODE)">1</column>
</item>
<item>
<column name="PRF_CODE">RDC_ENABLED</column>
<column name="COUNT(PRF_CODE)">1</column>
</item>
<item>
<column name="PRF_CODE">REP60_OP_PATH</column>
<column name="COUNT(PRF_CODE)">1</column>
</item>
<item>
<column name="PRF_CODE">REP_PATH</column>
<column name="COUNT(PRF_CODE)">1</column>
</item>
<item>
<column name="PRF_CODE">RPT_URL</column>
<column name="COUNT(PRF_CODE)">1</column>
</item>
<item>
<column name="PRF_CODE">SENDER_ID</column>
<column name="COUNT(PRF_CODE)">1</column>
</item>
<item>
<column name="PRF_CODE">SPECIAL_SHIP</column>
<column name="COUNT(PRF_CODE)">1</column>
</item>
<item>
<column name="PRF_CODE">SPR_MONTHS</column>
<column name="COUNT(PRF_CODE)">1</column>
</item>
<item>
<column name="PRF_CODE">TARGET_ID</column>
<column name="COUNT(PRF_CODE)">1</column>
</item>
<item>
<column name="PRF_CODE">TRIM_SCANNER_SPACES</column>
<column name="COUNT(PRF_CODE)">1</column>
</item>
<item>
<column name="PRF_CODE">UPDATE_OE</column>
<column name="COUNT(PRF_CODE)">1</column>
</item>
<item>
<column name="PRF_CODE">VENDOR_LOV_CHECK</column>
<column name="COUNT(PRF_CODE)">1</column>
</item>
<item>
<column name="PRF_CODE">WO_REPORT_FILLER</column>
<column name="COUNT(PRF_CODE)">1</column>
</item>
<item>
<column name="PRF_CODE">WO_RPT_PRINT_TC</column>
<column name="COUNT(PRF_CODE)">1</column>
</item>
</PivotSet>
答案 0 :(得分:2)
您需要XPath中的项目节点:
select a.prf_code
from myxmltab
cross join XMLTable('/PivotSet/item'
passing myxmltab.prf_code_xml
columns prf_Code varchar2(20) path 'column[1]'
) a;
PRF_CODE
--------------------
AR_GROUP_EMAIL_ID
AUTO_ASN_RECEIVE
AUTO_EMAIL_PREF
AUTO_INVOICE_PREF
...
我已经取出冗余的内联视图来简化它。而不是依赖列节点顺序始终相同(尽管这可能是一个有效的假设),您可以使用列名称:
columns prf_Code varchar2(20) path 'column[@name="PRF_CODE"]'
如果您想要两个列,则可以添加第二个术语:
select a.prf_code, a.quantity
from myxmltab
cross join XMLTable('/PivotSet/item'
passing myxmltab.prf_code_xml
columns prf_Code varchar2(20) path 'column[@name="PRF_CODE"]',
quantity number path 'column[@name="COUNT(PRF_CODE)"]'
) a;
PRF_CODE QUANTITY
-------------------- ----------
AR_GROUP_EMAIL_ID 1
AUTO_ASN_RECEIVE 1
AUTO_EMAIL_PREF 1
AUTO_INVOICE_PREF 1
...