I can use a bit of help from you. I have a table "card_activity" in oracle DB with
Columns:
INTERVENTION_ID NUMBER(13,0)
CARD_NUM NUMBER(19,0)
ACCOUNT_ID NUMBER(19,0)
REQUESTED_AMT NUMBER(8,2)
ACTUAL_AMT NUMBER(8,2)
AUTHORIZED_AMT NUMBER(8,2)
SITE_CD VARCHAR2(25 BYTE)
EXTERNAL_TRACE_ID VARCHAR2(12 BYTE)
EXTERNAL_BATCH_ID VARCHAR2(3 BYTE)
EXTERNAL_TICKET_ID VARCHAR2(4 BYTE)
EXTERNAL_TERMINAL_ID VARCHAR2(25 BYTE)
EXTERNAL_ACTIVITY_DT DATE
PAIRED_INTERVENTION_ID NUMBER(13,0)
REVERSAL_FLAG VARCHAR2(1 BYTE)
RECONCILE_INTERVENTION_ID NUMBER(13,0)
SALES_ORDER_INTERVENTION_ID NUMBER(13,0)
INVENTORY_INTERVENTION_ID NUMBER(13,0)
LAST_INTERVENTION_ID NUMBER(13,0)
EXT_XML CLOB
Data:
73141 7042310000000002253 36887 -20 -17.75 00303563 000001 001 0001 PLD0 31-AUG-2012 02.23.52 N <preRedeem><cplValue>5</cplValue><cplQuantity>355.0</cplQuantity><cplRequestedAmount>17.750</cplRequestedAmount><cplAuthorizedAmount>17.750</cplAuthorizedAmount><washValue>0</washValue><washRequestedAmount>10.00</washRequestedAmount><washAuthorizedAmount>0</washAuthorizedAmount><products><product><productCode>03</productCode><productType>F</productType><quantity>200.0</quantity><salesAmount>50.00</salesAmount><taxInclusiveFlag>I</taxInclusiveFlag><discountAmount>0.00</discountAmount><provinceCode>ON</provinceCode></product><product><productCode>W3</productCode><productType>C</productType><quantity>0.0</quantity><salesAmount>10.00</salesAmount><taxInclusiveFlag>E</taxInclusiveFlag><discountAmount>0.00</discountAmount><provinceCode>ON</provinceCode></product><product><productCode>05</productCode><productType>F</productType><quantity>155.0</quantity><salesAmount>25.50</salesAmount><taxInclusiveFlag>I</taxInclusiveFlag><discountAmount>0.00</discountAmount><provinceCode>ON</provinceCode></product></products></preRedeem>
73225 7042310000000002287 37541 -5 -0.2 00302289 015730 333 0853 LBR0 04-SEP-2012 10.01.50 N <preRedeem><cplValue>5</cplValue><cplMaxLitre>0</cplMaxLitre><cplQuantity>3.9</cplQuantity><cplRequestedAmount>0.195</cplRequestedAmount><cplAuthorizedAmount>0.195</cplAuthorizedAmount><washValue>0</washValue><washRequestedAmount>0</washRequestedAmount><washAuthorizedAmount>0</washAuthorizedAmount><products><product><productCode>20</productCode><productType>F</productType><quantity>3.9</quantity><salesAmount>5.00</salesAmount><taxInclusiveFlag>I</taxInclusiveFlag><discountAmount>0.00</discountAmount><provinceCode>ON</provinceCode></product></products></preRedeem>
Breaking up the xml 1st row:
<preRedeem>
<cplValue>5</cplValue>
<cplQuantity>355.0</cplQuantity>
<cplRequestedAmount>17.750</cplRequestedAmount>
<cplAuthorizedAmount>17.750</cplAuthorizedAmount>
<washValue>0</washValue>
<washRequestedAmount>10.00</washRequestedAmount>
<washAuthorizedAmount>0</washAuthorizedAmount>
<products>
<product>
<productCode>03</productCode>
<productType>F</productType>
<quantity>200.0</quantity>
<salesAmount>50.00</salesAmount>
<taxInclusiveFlag>I</taxInclusiveFlag>
<discountAmount>0.00</discountAmount>
<provinceCode>ON</provinceCode>
</product>
<product>
<productCode>W3</productCode>
<productType>C</productType>
<quantity>0.0</quantity>
<salesAmount>10.00</salesAmount>
<taxInclusiveFlag>E</taxInclusiveFlag>
<discountAmount>0.00</discountAmount>
<provinceCode>ON</provinceCode>
</product>
<product>
<productCode>05</productCode>
<productType>F</productType>
<quantity>155.0</quantity>
<salesAmount>25.50</salesAmount>
<taxInclusiveFlag>I</taxInclusiveFlag>
<discountAmount>0.00</discountAmount>
<provinceCode>ON</provinceCode>
</product>
</products>
</preRedeem>
2nd row:
<preRedeem>
<cplValue>5</cplValue>
<cplMaxLitre>0</cplMaxLitre>
<cplQuantity>3.9</cplQuantity>
<cplRequestedAmount>0.195</cplRequestedAmount>
<cplAuthorizedAmount>0.195</cplAuthorizedAmount>
<washValue>0</washValue>
<washRequestedAmount>0</washRequestedAmount>
<washAuthorizedAmount>0</washAuthorizedAmount>
<products>
<product>
<productCode>20</productCode>
<productType>F</productType>
<quantity>3.9</quantity>
<salesAmount>5.00</salesAmount>
<taxInclusiveFlag>I</taxInclusiveFlag>
<discountAmount>0.00</discountAmount>
<provinceCode>ON</provinceCode>
</product>
</products>
</preRedeem>
I need to write a query to extract "salesAmount" as a sum if multiple ("salesAmount") tags are present under EXT_XML attribute in a single row. I tried the following query just to extract SalesAmount (no aggregation).
Select
extract(xmltype.createxml(ext_xml), '/preRedeem/products/product/salesAmount/text()').getStringVal()
from card_activity
Output:
50.0010.0025.50
50.00
How do I modify my sql to get the
Desired Output:
85.50
50.0
Here is an example to start with. I assume that you will have multiple preRedeem elents in one XML record? Then is there some unique ID? You would need to change the query to also extract a relevant key id and group by that. If you edit your question to show that detail, I will try to update my answer.