Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extract data from XML Clob using SQL from Oracle Database

I want to extract the value of Decision using sql from table TRAPTABCLOB having column testclob with XML stored as clob.

Sample XML as below.

        <?xml version="1.0" encoding="UTF-8"?>
<DCResponse>
    <Status>Success</Status>
    <Authentication>
        <Status>Success</Status>
    </Authentication>
    <ResponseInfo>
        <ApplicationId>5701200</ApplicationId>
        <SolutionSetInstanceId>
                        63a5c214-b5b5-4c45-9f1e-b839a0409c24
                    </SolutionSetInstanceId>
        <CurrentQueue />
    </ResponseInfo>
    <ContextData>
        <!--Decision Details Start-->
        <Field key="SoftDecision">A</Field>
        <Field key="**Decision**">1</Field>
        <Field key="NodeNo">402</Field>
        <Field key="NodeDescription" />
        <!--Decision Details End-->
        <!--Error Details Start-->
        <Field key="ErrorResponse">
            <Response>
                <Status>[STATUS]</Status>
                <ErrorCode>[ERRORCODE]</ErrorCode>
                <ErrorDescription>[ERRORDESCRIPTION]</ErrorDescription>
                <Segment>[SEGMENT]</Segment>
            </Response>
        </Field>
        <Field key="ErrorCode">0</Field>
        <Field key="ErrorDescription" />
    </ContextData>
</DCResponse>
like image 319
mitrabhanu Avatar asked Nov 28 '12 08:11

mitrabhanu


2 Answers

Try

SELECT EXTRACTVALUE(xmltype(testclob), '/DCResponse/ContextData/Field[@key="Decision"]') 
FROM traptabclob;

Here is a sqlfiddle demo

like image 184
A.B.Cade Avatar answered Nov 05 '22 10:11

A.B.Cade


This should work

SELECT EXTRACTVALUE(column_name, '/DCResponse/ContextData/Decision') FROM traptabclob;

I have assumed the ** were just for highlighting?

like image 41
A. Gilfrin Avatar answered Nov 05 '22 08:11

A. Gilfrin