XMLRoot desupport

XMLRoot has been deprecated since 12cR2 and desupported since 21c. Still, it is not really obvious to understand how to generate a prolog.

Also, you couldn’t specify the encoding.

Well, one could fake the version with double quote, but this is not recommended, there even was some dirty SQL injection in oldish versions.

select xmlroot(xmlelement(x),version '1.0" encoding="utf-8');
<?xml version="1.0" encoding="utf-8"?>
<X/>

But this is a hack,

XMLSERIALIZE is the recommended approach.

Once converted to CLOB, BLOB, Varchar2, the version can be specified, or default to 1.0.

select to_clob(xmlserialize(document xmlelement(x) version '1.0'));
<?xml version="1.0"?>
<X/>

The ‘1.0″ encoding “utf-8’ still works, but it is still a hack and not the way to go.
There is an encoding clause, but this is for binary content. If you want to generate a specific encoding in the prolog, convert it blob first and back to clob (do you really want to do that?).

select to_clob(xmlserialize(
  document xmlelement(foo) as blob 
  encoding 'us-ascii'));
<?xml version="1.0" encoding="US-ASCII"?>
<FOO/> 

select to_clob(xmlserialize(
  document xmlelement(foo) as blob 
  encoding 'utf-16be'),
  nls_charset_id('AL16UTF16'));
<?xml version="1.0" encoding="UTF-16BE"?>
<FOO/>

Also note, there is XML 1.0, XML 1.1, XML 2.0, but everybody uses 1.0. There is no work done on 2.0 and 1.1 is for very strange tags with special characters (things you cannot even type on your keyboard) .

Version is also not checked, at least in Oracle 23c.

select xmlserialize(document xmlelement("x") version '42');
<?xml version="42"?>
<x/>