Search code examples
sqlxmloracle-databaseextract-value

Extract value from XML


I am using this query to extract the value from the XML

SELECT extractvalue(column_value, '/TransactionLimitDTO/idTxn') "TxnId"
FROM TABLE(XMLSequence(XMLType(mg.limits)
            .extract('/ModifyTransactionLimitRequestDTO/transactionLimit/TransactionLimitDTO'))) t,Mstgloballimitspackage mg

But, I'm getting an error:

ORA-00904: "MG"."LIMITS": invalid identifier

Could you please tell me how can I resolve this?

I tried this:

 SELECT extractvalue(column_value, '/TransactionLimitDTO/idTxn') "TxnId"
 FROM TABLE(XMLSequence(XMLType(select mg.limits from Mstgloballimitspackage mg)
                          .extract('/ModifyTransactionLimitRequestDTO/transactionLimit/TransactionLimitDTO'))) t

but this is also not working.

When I put a complete XML file in the place of mg.limits I get a too long string literal as a argument error.

It is working whenever I place a small piece of XML in the place of mg.limits.


Solution

  • This will work:

     SELECT extractvalue(t.column_value, '/TransactionLimitDTO/idTxn') "TxnId"
         FROM Mstgloballimitspackage mg,
              TABLE(XMLSequence(XMLType(mg.limits,'')
                                .extract('/ModifyTransactionLimitRequestDTO/transactionLimit/TransactionLimitDTO'))) t