简体   繁体   English

Oracle - 提取 XML 版本和 XML Z832688F4DF3AB7750CDB699AAA07FCType4 中的编码

[英]Oracle - extracting XML version and encoding from XML prolog in XMLType

Let's say we have following XMLType in Oracle:假设我们在 Oracle 中有以下 XMLType:

<?xml version="1.0" encoding="UTF-8"?>
<root>
</root>

I need to get XML version and encoding values or whole XML prolog preferably with XML functions, f.我需要获得 XML 版本和编码值或整个 XML prolog 最好使用 Z3501BB093D363810B67CFEDf.059B 功能ex.前任。 XMLTABLE. XML 表。 Is that possible?那可能吗? Or only with string/CLOB functions?还是仅使用字符串/CLOB 函数?

We use Oracle 19c.我们使用 Oracle 19c。

Is that possible?那可能吗?

No, unfortunately, it isn't, because XML functions like XMLTable work with XMLType which parses your input xml (from your NLS_LANG charset if it is CLOB or Varchar2, and from specified charset if it is BLOB) and store it in own internal codepage and when you get it, oracle returns it in your NLS_LANG:不,不幸的是,它不是,因为像 XMLTable 这样的 XML 函数与 XMLType 一起使用,它解析您的输入 xml(如果它是 CLOB 或 Varchar2,则来自您的 NLS_LANG 字符集,如果它是 BLOB 则来自指定的字符集)并将其存储在自己的内部代码页中当你得到它时,oracle 在你的 NLS_LANG 中返回它:

SQL> with v as (select q'[<?xml version="1.1" encoding="blabla"?><root/>]' as vXML from dual)
  2  select xmltype(vXML) x from v;

X
------------------------------------------------
<?xml version="1.1" encoding="US-ASCII"?>
<root/>

And look what if I change my NLS_LANG to UTF8:看看如果我将 NLS_LANG 更改为 UTF8 会怎样:

SQL> with v as (select q'[<?xml version="1.1" encoding="blabla"?><root/>]' as vXML from dual)
  2  select xmltype(vXML) x from v;

X
-----------------------------------------
<?xml version="1.1" encoding="UTF-8"?>
<root/>


SQL> ! env | grep NLS_LANG
NLS_LANG=american_america.UTF8

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM