3

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

3 Answers 3

5
select xmlroot (xmltype ('<poid>143598</poid>')
                  , version '1.0" encoding="UTF-8'
                  ) "XMLRoot"
  from dual;
Sign up to request clarification or add additional context in comments.

2 Comments

you can not pass encoding in such a way, at least for oracle 12c
Yes you can, atleast in 11g. This is an answer from 2012.
1

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>

Comments

0

It is easy but let me explain the possible logic of Oracle:

Character data are stored in database encoding by default. If you want to specify encoding then probable it is different from database encoding. OK, Let it be BLOB, i.e. octet stream represented in desired encoding. So we should use XMLSERIALIZE function to create representation in any encoding (including the default DB encoding as well)

select  
  xmlserialize(document xmltype('<Envelop>Any UTF charachers. Tous les caractères UTF. כל תווי UTF </Envelop>') as blob encoding 'UTF-8' version '1.0')
from dual;

If your default DB encoding is UTF-8 then you can also wrap this call into to_clob(…) or even to_char(…) to see the result. For me

select  
  to_char(xmlserialize(document xmltype('<Envelop>Any UTF charachers. Tous lescaractères UTF. כל תווי UTF </Envelop>') as blob encoding 'UTF-8' version '1.0'))
from dual;

Gives:

<?xml version="1.0" encoding="UTF-8"?>
<Envelop>Any UTF charachers. Tous les caractères UTF. כל תווי UTF </Envelop>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.