EXISTSNODE¶
说明¶
该函数用于确定特定的XML节点的路径是否存在,返回0表示节点不存在,返回1表示节点存在。(兼容Oracle)
返回值:¶
若xpath指向xml数据中节点则返回1,否则返回0。
示例¶
示例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)