sql >> Base de Datos >  >> RDS >> Oracle

Cómo abrir datos XML en Oracle

un par de métodos se describen en este SO:

Oracle Pl/SQL:recorrer nodos XMLTYPE

Actualización: es bastante sencillo ya que ambos métodos son SQL puro (puede llamar a este SQL desde PL/SQL o cualquier herramienta que interactúe con la base de datos):

SQL> WITH openedXml AS (
  2  SELECT extractvalue(column_value, '/theRow/First') FIRST,
  3         extractvalue(column_value, '/theRow/Last') LAST,
  4         to_number(extractvalue(column_value, '/theRow/Age')) Age
  5    FROM TABLE(XMLSequence(XMLTYPE('<theRange>
  6      <theRow><First>Bob</First><Last>Smith</Last><Age>30</Age></theRow>
  7      <theRow><First>Sue</First><Last>Jones</Last><Age>34</Age></theRow>
  8      <theRow><First>John</First><Last>Bates</Last><Age>40</Age></theRow>
  9  </theRange>').extract('/theRange/theRow')))
 10  )
 11  SELECT *
 12    FROM openedxml
 13   WHERE age BETWEEN 30 AND 35;

FIRST     LAST       AGE
--------- -------- -----
Bob       Smith       30
Sue       Jones       34