sql >> Database >  >> RDS >> Oracle

Ontleden SOAP XML in Oracle met voorbeeld

U kunt de inhoud van het knooppunt extraheren met XMLQUERY :

select xmlquery('declare namespace soapenv = "http://schemas.xmlsoap.org/soap/envelope/";
      declare namespace urn = "urn:ABC";
      /soapenv:Envelope/soapenv:Body/urn:settleResponse/settleReturn/message/text()'
    passing XMLType(message)
    returning content) as message,
  xmlquery('declare namespace soapenv = "http://schemas.xmlsoap.org/soap/envelope/";
      declare namespace urn = "urn:ABC";
      /soapenv:Envelope/soapenv:Body/urn:settleResponse/settleReturn/errorCode/text()'
    passing XMLType(message)
    returning content) as errorCode,
  xmlquery('declare namespace soapenv = "http://schemas.xmlsoap.org/soap/envelope/";
      declare namespace urn = "urn:ABC";
      /soapenv:Envelope/soapenv:Body/urn:settleResponse/settleReturn/status/text()'
    passing XMLType(message)
    returning content) as status
from external;

MESSAGE              ERRORCODE            STATUS   
-------------------- -------------------- ----------
Missing first name   INVALID_ACC          Failed

Of misschien eenvoudiger, vooral als u meerdere berichten moet verwerken, met XMLTABLE :

select x.*
from external ext
cross join xmltable(
  xmlnamespaces('http://schemas.xmlsoap.org/soap/envelope/' as  "soapenv",
    'urn:ABC' as "urn"),
  '/soapenv:Envelope/soapenv:Body/urn:settleResponse/settleReturn'
  passing XMLType(ext.message)
  columns message varchar2(20) path 'message',
    errorCode varchar2(20) path 'errorCode',
    status varchar2(10) path 'status'
) x;

MESSAGE              ERRORCODE            STATUS   
-------------------- -------------------- ----------
Missing first name   INVALID_ACC          Failed    

In beide gevallen moet u de naamruimten specificeren, en de syntaxis is anders. Lees meer over het gebruik van deze functies .

U kunt deze rechtstreeks in een andere tabel invoegen met insert into some_table (x, y, z) select ... .




  1. Wat zijn PLSQL-records in Oracle?

  2. Meerdere JPA-transacties parallel uitvoeren

  3. Canonical:HTML-formuliergegevens opslaan in MySQL-database

  4. MySQL - Rangschikking per maand over meerdere maanden