EXISTSNODE

说明

该函数用于确定特定的XML节点的路径是否存在,返回0表示节点不存在,返回1表示节点存在。(兼容Oracle)

语法

existsnode ::=

参数

XMLType_instance

用于指定XMLType实例

Xpath_string

用于指定XML节点路径

返回值:

若xpath指向xml数据中节点则返回1,否则返回0。

注释:

该函数暂不支持指定namespace

EXISTSNODE可以在pl中通过变量调用,xmldata.existsnode(XPath_string)

示例

示例1:

create or replace function existsnode_test(xmlVar xmltype, xpathStr
varchar2) return integer is
bExists integer;
begin
bExists := xmlVar.existsnode(xpathStr);
return bExists;
end;
/

SQL> select existsnode_test(xmltype('<aa><bb>afeafe</bb><cc>ccc</cc></aa>'),'/aa/bb') from dual;
EXISTSNODE_TEST
-----------------
            1
(1 row)

示例2:

Create TABLE EMPLOYEES
(
  id     NUMBER,
  data   XMLTYPE
);

Insert INTO EMPLOYEES
VALUES (1, xmltype ('<Employees>
<Employee emplid="1111" type="admin">
    <firstname>John</firstname>
    <lastname>Watson</lastname>
    <age>30</age>
    <email>johnwatson@sh.com</email>
</Employee>
<Employee emplid="2222" type="admin">
    <firstname>Sherlock</firstname>
    <lastname>Homes</lastname>
    <age>32</age>
    <email>sherlock@sh.com</email>
</Employee>
<Employee emplid="3333" type="user">
    <firstname>Jim</firstname>
    <lastname>Moriarty</lastname>
    <age>52</age>
    <email>jim@sh.com</email>
</Employee>
<Employee emplid="4444" type="user">
    <firstname>Mycroft</firstname>
    <lastname>Holmes</lastname>
    <age>41</age>
    <email>mycroft@sh.com</email>
</Employee>
</Employees>'));

SQL> SELECT existsnode(data,'/Employees/Employee') node FROM EMPLOYEES;
 NODE
 ------
     1
 (1 row)