Oracle SQL XML Functions - How to get encoding in

2019-07-04 04:43发布

问题:

This SQL

SELECT XMLRoot(XMLType('<poid>143598</poid>'), VERSION '1.0', STANDALONE YES)
  AS xmlroot FROM DUAL; 

generates an output as follows

XMLROOT
--------------------------------------
<?xml version="1.0" standalone="yes"?>
<poid>143598</poid>

How can get encoding in my xml prolog?

Ex - I want output to be something like

XMLROOT
--------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<poid>143598</poid>

Reference -

Generate XML Data from the database

回答1:

select xmlroot (xmltype ('<poid>143598</poid>')
                  , version '1.0" encoding="UTF-8'
                  ) "XMLRoot"
  from dual;


回答2:

Weird ... but looks like version argument can have anything in it -

replace

version '1.0'

with

version '1.0" encoding="utf-8'

output

XMLROOT
--------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<poid>143598</poid>