XML looks like this:
<TaxRuleConditionVO>
<TaxRuleConditionVORow>
<ConditionGroupCode>SU CC 37,69</ConditionGroupCode>
<TaxParameterCode>ACCOUNT</TaxParameterCode>
<DataTypeCode>ALPHANUMERIC</DataTypeCode>
<DeterminingFactorClassCode>ACCOUNTING_FLEXFIELD</DeterminingFactorClassCode>
<DeterminingFactorCqCode null="true"/>
<OperatorCode>=</OperatorCode>
<RecordTypeCode>USER_DEFINED</RecordTypeCode>
<IgnoreFlag>N</IgnoreFlag>
<DateValue null="true"/>
<AlphanumericValue null="true"/>
<ValueLow null="true"/>
<ValueHigh null="true"/>
<CreationDate>2023-07-06 16:06:08.604</CreationDate>
<LastUpdateDate>2023-07-06 17:04:14.235</LastUpdateDate>
<CreatedBy>stuartd</CreatedBy>
<LastUpdatedBy>stuartd</LastUpdatedBy>
<LastUpdateLogin>FFC4CEC7678DF531E0534D60410A1325</LastUpdateLogin>
<ProgramAppName null="true"/>
<ProgramName null="true"/>
<DeterminingFactorCode>LINE_ACCOUNT</DeterminingFactorCode>
<NumericValueTrans null="true"/>
<FlexFilterValue><?xml version="1.0" encoding="UTF-8"?> <FndFilter xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.oracle.com/apps/fnd/applcore/filter/FndFilter.xsd"> <KeyFlexFilter> <keyFlexfieldCode>GL#</keyFlexfieldCode> <structureInstanceCode>SUN</structureInstanceCode> <applicationShortName>GL</applicationShortName> <filterCriteriaRow> <filterCriteriaItem> <attributeName>sunCostcentre</attributeName> <columnName>SEGMENT2</columnName> <operator>EQUALTO</operator> <conjunction>AND</conjunction> <valueDataType>STRING</valueDataType> <value>85502</value> </filterCriteriaItem> <conjunction>AND</conjunction> </filterCriteriaRow> </KeyFlexFilter> </FndFilter> </FlexFilterValue>
<TaxRuleConditionDetails null="true"/>
</TaxRuleConditionVORow>
The column I need lies between <value> and </value>, but this lies inside an xmltype column called Flexfiltervalue.
How do I write the sql to extract that value and it's related ConditionGroupCode
I have tried various options
select t.CONDITION_GROUP_CODE as ConditionGroupCode, instr((t.FLEX_FILTER_VALUE).getClobVal(),''), instr((t.FLEX_FILTER_VALUE).getClobVal(),''))as clobval from ZX_CONDITIONS t where t.condition_group_code = 'SU CC 50 1'
THIS RETURNED THE WRONG VALUE
SELECT t.FLEX_FILTER_VALUE.getStringVal() FROM ZX_CONDITIONS t
THIS PRODUCED AN ERROR: ORA-19011: Character string buffer too small ORA-06512: at "SYS.XMLTYPE", line 169
select extract(t.FLEX_FILTER_VALUE, '/').getClobVal(), <'value>' from ZX_CONDITIONS t
THIS GIVES ME MISSING EXPRESISON ERROR
You can use the XMLQuery function to search inside an XML document. Pass it the path your searching for.
The example XML document is invalid, so here's a slightly adapted version:
with rws as (
select xmltype ('
<TaxRuleConditionVORow>
<ConditionGroupCode>SU CC 37,69</ConditionGroupCode>
<TaxParameterCode>ACCOUNT</TaxParameterCode>
<DataTypeCode>ALPHANUMERIC</DataTypeCode>
<DeterminingFactorClassCode>ACCOUNTING_FLEXFIELD</DeterminingFactorClassCode>
<DeterminingFactorCqCode null="true"/>
<OperatorCode>=</OperatorCode>
<RecordTypeCode>USER_DEFINED</RecordTypeCode>
<IgnoreFlag>N</IgnoreFlag>
<DateValue null="true"/>
<AlphanumericValue null="true"/>
<ValueLow null="true"/>
<ValueHigh null="true"/>
<CreationDate>2023-07-06 16:06:08.604</CreationDate>
<LastUpdateDate>2023-07-06 17:04:14.235</LastUpdateDate>
<CreatedBy>stuartd</CreatedBy>
<LastUpdatedBy>stuartd</LastUpdatedBy>
<LastUpdateLogin>FFC4CEC7678DF531E0534D60410A1325</LastUpdateLogin>
<ProgramAppName null="true"/>
<ProgramName null="true"/>
<DeterminingFactorCode>LINE_ACCOUNT</DeterminingFactorCode>
<NumericValueTrans null="true"/>
<FlexFilterValue>
<FndFilter>
<KeyFlexFilter>
<keyFlexfieldCode>GL#</keyFlexfieldCode>
<structureInstanceCode>SUN</structureInstanceCode>
<applicationShortName>GL</applicationShortName>
<filterCriteriaRow>
<filterCriteriaItem>
<attributeName>sunCostcentre</attributeName>
<columnName>SEGMENT2</columnName>
<operator>EQUALTO</operator>
<conjunction>AND</conjunction>
<valueDataType>STRING</valueDataType>
<value>85502</value>
</filterCriteriaItem>
<conjunction>AND</conjunction>
</filterCriteriaRow>
</KeyFlexFilter>
</FndFilter>
</FlexFilterValue>
<TaxRuleConditionDetails null="true"/>
</TaxRuleConditionVORow>') x from dual
)
select xmlquery (
'/TaxRuleConditionVORow/FlexFilterValue/FndFilter/KeyFlexFilter/filterCriteriaRow/filterCriteriaItem/value'
passing x returning content
).getClobVal() val
from rws;
VAL
<value>85502</value>