Dear
I have tried to parse a clob field located in a Oracle table that contains a envelope and also some HTML characters (", <, >), as shown below:
<?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="
http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="
http://www.w3.org/2001/XMLSchema" xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance" ><soapenv:Body><inputXmlReturn xmlns="
http://invoker.ps.eos.fairisaac.com" ><?xml version="1.0" encoding="UTF-8"?><Application APPLICATIONCROSSREFERENCEID="111222" DeliveryOptionCode="Test"><MessageList StatusCode="0" StatusDescription="Successful"/><CreditApprovalProcess AmountFinanced="1000"TransactionCnt="1"><ApList/><RevenueSources><RevenueSource RevenueSourceType="Cana"/> </RevenueSources><EquipmentList> <Equipment EquipLoanTerm="60" EquipModel="AAAAA" EquipNewOrUsed="N" EquipSellingPrice="1000" EquipType="Test"/> </EquipmentList><ApplicantList> <Applicant StartDtBusiness="1900-01-01"><InstallmentList/> </Applicant> <Applicant StartDtTest="1900-01-01"><InstallmentList/> </Applicant> </ApplicantList> </CreditApprovalProcess><CreditRequest ProductCategory="cat_Generic" ProductCode="prod_XXX"/><DecisionResponse> <Product DecisionFlowName="df_test_Ag" LastStepName="rs_Test" OriginType="Request" ProductCategory="cat_Generic" ProductCode="prod_XXX" ProductStatusIndicator="Complete" StrategyName=""> <Decision DecisionIndex="0" DecisionResult="Investigate" DecisionStatusIndicator="Final" ImplementationName="rs_Test" ImplementationType="Ruleset"> <Reason RankOrderNumber="2"> <ReasonText>Test</ReasonText> </Reason> <Reason RankOrderNumber="3"> <ReasonText>Test</ReasonText> </Reason> </Decision> </Product> </DecisionResponse><ProcessingHistory ProcessingTimestamp="2017-04-25T08:53:37.202-03:00" SystemId="Test"> <DecisionFlowHistory DecisionFlowName="df_Test_Ag" ProductCategory="cat_Generic" ProductCode="prod_XXX" StartTimestamp="2017-04-25T08:53:37.204-03:00" StopTimestamp="2017-04-25T08:53:37.205-03:00" SystemDecisionResult="Investigate"> <DecisionFlowStepHistory ImplementationName="dms_InitialDefaults" ImplementationType="Data Method Sequence" StartTimestamp="2017-04-25T08:53:37.204-03:00" StepName="dms_InitialDefaults" StopTimestamp="2017-04-25T08:53:37.204-03:00"> <DataMethodSequenceHistory DataMethodSequenceName="dms_InitialDefaults"/> </DecisionFlowStepHistory> <DecisionFlowStepHistory ImplementationName="rs_Test" ImplementationType="Ruleset" StartTimestamp="2017-04-25T08:53:37.204-03:00" StepName="rs_Test" StopTimestamp="2017-04-25T08:53:37.205-03:00"> <RulesetHistory RulesFiredTotalSeverity="2" RulesetName="rs_Test" RulesetResult="RuleFails"> <RuleHistory ReasonText="Test" RuleName="rule_SerasaBureauCheck"/><RuleHistory ReasonText="Test" RuleName="rule_BacenBureauCheck"/> <DecisionHistory DecisionResult="Investigate"/> </RulesetHistory> </DecisionFlowStepHistory> </DecisionFlowHistory> </ProcessingHistory><DataMethodHistory Timestamp="2017-04-25T08:53:37.205-03:00"> <Name>dm_FinancialDataCheck</Name> <DataType>boolean</DataType> <Value>false</Value> </DataMethodHistory> </Application></inputXmlReturn></soapenv:Body></soapenv:Envelope>
Basically, I'd like to extract all data stored in every single attribute value, for instance:
APPLICATIONCROSSREFERENCEID="111222"
It should result in:
APPLICATIONCROSSREFERENCEID 111222
Could you please provide me some example to do that in a Select Oracle?
Regards,
Raphael
The following will extract the input and return an xmltype
SQL>
SQL> set define off
SQL>
SQL> select xmltype(p.field1)
2 from (
3 select xmltype(
4 '<?xml version="1.0" encoding="utf-8"?>'
5 ||'<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope">'
6 ||'<soapenv:Body>'
7 ||'<inputXmlReturn xmlns="http://invoker.ps.eos.fairisaac.com">'
8 ||'<?xml version="1.0" encoding="UTF-8"?><Application APPLICATIONCROSSREFERENCEID="111222" DeliveryOptionCode="Test"><MessageList StatusCode="0'
9 ||'" StatusDescription="Successful"/><CreditApprovalProcess AmountFinanced="1000" TransactionCnt="1"><ApList/><RevenueSources><RevenueSource RevenueSourceType="Cana"'
10 ||'/> </RevenueSources><EquipmentList> <Equipment EquipLoanTerm="60" EquipModel="AAAAA" EquipNewOrUsed="N" EquipSellingPrice="1000" EquipType="Test"/> </'
11 ||'EquipmentList><ApplicantList> <Applicant StartDtBusiness="1900-01-01"><InstallmentList/> </Applicant> <Applicant StartDtTest="1900-01-01"><InstallmentList/> </Applicant> </'
12 ||'ApplicantList> </CreditApprovalProcess><CreditRequest ProductCategory="cat_Generic" ProductCode="prod_XXX"/><DecisionResponse> <Product DecisionFlowName="df_test_Ag" LastStepName='
13 ||'"rs_Test" OriginType="Request" ProductCategory="cat_Generic" ProductCode="prod_XXX" ProductStatusIndicator="Complete" StrategyName=""> <Decision DecisionIndex='
14 ||'"0" DecisionResult="Investigate" DecisionStatusIndicator="Final" ImplementationName="rs_Test" ImplementationType="Ruleset"> <Reason RankOrderNumber="2"> <'
15 ||'ReasonText>Test</ReasonText> </Reason> <Reason RankOrderNumber="3"> <ReasonText>Test</ReasonText> </Reason> </Decision> </Product> </DecisionResponse><'
16 ||'ProcessingHistory ProcessingTimestamp="2017-04-25T08:53:37.202-03:00" SystemId="Test"> <DecisionFlowHistory DecisionFlowName="df_Test_Ag" ProductCategory="cat_Generic" ProductCode="'
17 ||'prod_XXX" StartTimestamp="2017-04-25T08:53:37.204-03:00" '
18 ||'StopTimestamp="2017-04-25T08:53:37.205-03:00" SystemDecisionResult="Investigate"> <DecisionFlowStepHistory ImplementationName="dms_InitialDefaults" ImplementationType='
19 ||'"Data Method Sequence" StartTimestamp="2017-04-25T08:53:37.204-03:00" StepName="dms_InitialDefaults" StopTimestamp="2017-04-25T08:53:37.204-03:00"> <DataMethodSequenceHistory DataMethodSequenceName'
20 ||'="dms_InitialDefaults"/> </DecisionFlowStepHistory> <DecisionFlowStepHistory ImplementationName="rs_Test" ImplementationType="Ruleset" StartTimestamp="2017-04-25T08:53:37.204-03:00" StepName'
21 ||'="rs_Test" StopTimestamp="2017-04-25T08:53:37.205-03:00"> <RulesetHistory RulesFiredTotalSeverity="2" RulesetName="rs_Test" RulesetResult="RuleFails"> <RuleHistory ReasonText='
22 ||'"Test" RuleName="rule_SerasaBureauCheck"/><RuleHistory ReasonText="Test" RuleName="rule_BacenBureauCheck"/> <DecisionHistory DecisionResult="Investigate"/> </'
23 ||'RulesetHistory> </DecisionFlowStepHistory> </DecisionFlowHistory> </ProcessingHistory><DataMethodHistory Timestamp="2017-04-25T08:53:37.205-03:00"> <Name>dm_FinancialDataCheck</Name> <'
24 ||'DataType>boolean</DataType> <Value>false</Value> </DataMethodHistory> </Application>'
25 ||'</inputXmlReturn>'
26 ||'</soapenv:Body>'
27 ||'</soapenv:Envelope>') as xml
28 from dual ) t,
29 xmltable(
30 xmlnamespaces('http://schemas.xmlsoap.org/soap/envelope' as "soapenv",
31 DEFAULT 'http://invoker.ps.eos.fairisaac.com'
32 ),
33 '/soapenv:Envelope/soapenv:Body' passing t.xml
34 columns
35 field1 varchar2(4000) path 'inputXmlReturn') p;
XMLTYPE(P.FIELD1)
----------------------------------------------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="WINDOWS-1252"?>
<Application APPLICATIONCROSSREFERENCEID="111222" DeliveryOptionCode="Test">
<MessageList StatusCode="0" StatusDescription="Successful"/>
<CreditApprovalProcess AmountFinanced="1000" TransactionCnt="1">
<ApList/>
<RevenueSources>
<RevenueSource RevenueSourceType="Cana"/>
</RevenueSources>
<EquipmentList>
<Equipment EquipLoanTerm="60" EquipModel="AAAAA" EquipNewOrUsed="N" EquipSellingPrice="1000" EquipType="Test"/>
</EquipmentList>
<ApplicantList>
<Applicant StartDtBusiness="1900-01-01">
<InstallmentList/>
</Applicant>
<Applicant StartDtTest="1900-01-01">
<InstallmentList/>
</Applicant>
</ApplicantList>
</CreditApprovalProcess>
<CreditRequest ProductCategory="cat_Generic" ProductCode="prod_XXX"/>
<DecisionResponse>
<Product DecisionFlowName="df_test_Ag" LastStepName="rs_Test" OriginType="Request" ProductCategory="cat_Generic" ProductCode="
prod_XXX" ProductStatusIndicator="Complete" StrategyName="">
<Decision DecisionIndex="0" DecisionResult="Investigate" DecisionStatusIndicator="Final" ImplementationName="rs_Test" Implem
entationType="Ruleset">
<Reason RankOrderNumber="2">
<ReasonText>Test</ReasonText>
</Reason>
<Reason RankOrderNumber="3">
<ReasonText>Test</ReasonText>
</Reason>
</Decision>
</Product>
</DecisionResponse>
<ProcessingHistory ProcessingTimestamp="2017-04-25T08:53:37.202-03:00" SystemId="Test">
<DecisionFlowHistory DecisionFlowName="df_Test_Ag" ProductCategory="cat_Generic" ProductCode="prod_XXX" StartTimestamp="2017-0
4-25T08:53:37.204-03:00" StopTimestamp="2017-04-25T08:53:37.205-03:00" SystemDecisionResult="Investigate">
<DecisionFlowStepHistory ImplementationName="dms_InitialDefaults" ImplementationType="Data Method Sequence" StartTimestamp="
2017-04-25T08:53:37.204-03:00" StepName="dms_InitialDefaults" StopTimestamp="2017-04-25T08:53:37.204-03:00">
<DataMethodSequenceHistory DataMethodSequenceName="dms_InitialDefaults"/>
</DecisionFlowStepHistory>
<DecisionFlowStepHistory ImplementationName="rs_Test" ImplementationType="Ruleset" StartTimestamp="2017-04-25T08:53:37.204-0
3:00" StepName="rs_Test" StopTimestamp="2017-04-25T08:53:37.205-03:00">
<RulesetHistory RulesFiredTotalSeverity="2" RulesetName="rs_Test" RulesetResult="RuleFails">
<RuleHistory ReasonText="Test" RuleName="rule_SerasaBureauCheck"/>
<RuleHistory ReasonText="Test" RuleName="rule_BacenBureauCheck"/>
<DecisionHistory DecisionResult="Investigate"/>
</RulesetHistory>
</DecisionFlowStepHistory>
</DecisionFlowHistory>
</ProcessingHistory>
<DataMethodHistory Timestamp="2017-04-25T08:53:37.205-03:00">
<Name>dm_FinancialDataCheck</Name>
<DataType>boolean</DataType>
<Value>false</Value>
</DataMethodHistory>
</Application>
1 row selected.
SQL>
SQL>
SQL>
SQL>
Now that you have an xmltype, you can use XMLTABLE to extract the columns as if it were normal XML.
Search this site for XMLTABLE for plenty of examples