Preview:
Estructura general:

xmlelement(name libros, ...): crea un elemento XML raíz llamado <libros>.

xmlagg(...): agrega múltiples elementos XML dentro del elemento raíz.

xmlelement(name libro, xmlforest(...)): crea un elemento <libro> con varios subelementos para los campos del libro.

SELECT
  xmlelement(
    name libros,
    xmlagg(
      xmlelement(
        name libro,
        xmlforest(
          id,
          titulo,
          autor,
          anio
        )
      )
    )
  ) AS libros_xml
FROM libros;
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter