Getting error while using ExtractValue function. [message #636570] |
Tue, 28 April 2015 07:25 |
|
Asfakul
Messages: 43 Registered: July 2014
|
Member |
|
|
Hi All, I was trying to use ExtractValue function to extract a node. But I am getting an error which I cant understand.
CREATE TABLE EMPLOYEES
(
id NUMBER,
data XMLTYPE
);
INSERT INTO EMPLOYEES
VALUES (1, xmltype ('<employees>
<employee type="admin" emplid="1111">
<firstname>John</firstname>
<lastname>Watson</lastname>
<age>30</age>
<email>johnwatson@sh.com</email>
</employee>
<employee type="admin" emplid="2222">
<firstname>Sherlock</firstname>
<lastname>Homes</lastname>
<age>32</age>
<email>sherlock@sh.com</email>
</employee>
<employee type="user" emplid="3333">
<firstname>Jim</firstname>
<lastname>Moriarty</lastname>
<age>52</age>
<email>jim@sh.com</email>
</employee>
<employee type="user" emplid="4444">
<firstname>Mycroft</firstname>
<lastname>Holmes</lastname>
<age>41</age>
<email>mycroft@sh.com</email>
</employee>
</employees>'));
Here is what I was trying.
select extractValue(e.data,'/employees/employee/firstname')
from employees e;
Please let me know what's the correct way to use ExtractValue and why should we use it instead of XMLTable function.
|
|
|
|
|
Re: Getting error while using ExtractValue function. [message #636577 is a reply to message #636576] |
Tue, 28 April 2015 08:45 |
|
Michel Cadot
Messages: 68732 Registered: March 2007 Location: Saint-Maur, France, https...
|
Senior Member Account Moderator |
|
|
This is the same thing, choose the way you prefer.
Note that xmltable allows you to type the returned columns when extractvalue just return a big VARCHAR2.
In addition, xmltable has many other options and features, it is a wrapper for the other xml functions.
If you don't know xmlsequence and other xml functions, I advise you to first study xmltable.
|
|
|