Oracle:如何使用XMLElement()在特定命名空间中创建元素

ave*_*net 1 xml oracle

在Oracle中,您可以使用XMLElement()函数创建元素,如下所示:

XMLElement('name', 'John')
Run Code Online (Sandbox Code Playgroud)

但是如何在特定命名空间中创建元素?例如,如何创建以下元素:

<my:name xmlns:my="http://www.example.com/my">John</my:name>
Run Code Online (Sandbox Code Playgroud)

Cra*_*aig 9

您还可以使用XMLAttribute:

select xmlelement("my:name",
        xmlattributes('http://www.example.com/my' as "xmlns:my"),
        'John'
       )
from dual
Run Code Online (Sandbox Code Playgroud)

将返回:

<my:name xmlns:my="http://www.example.com/my">John</my:name>
Run Code Online (Sandbox Code Playgroud)

您还可以检查Oracle是否将其识别为命名空间(除了您没有获得名称空间前缀"我的"未声明错误):

select xmlelement("my:name",
        xmlattributes('http://www.example.com/my' as "xmlns:my"),
        'John'
       ).getnamespace()
from dual
Run Code Online (Sandbox Code Playgroud)

将返回:

http://www.example.com/my
Run Code Online (Sandbox Code Playgroud)