Consider the following XML :
<Employee>
<EmpDetails>
<Name>huff</Name>
</EmpDetails>
</Employee>
Above XMLis stored as a column(DATA)
with data type [XML NULLABLE]
in a table in DB2.
Assume that the structure of the table is something like this:
Table name: REGEVENT
Columns are: REFID (VARCHAR), APPID(VARCHAR), DATA(XML NULLABLE)
Suppose the value in the table is: REFID(12345)
, APPID(54321)
, DATA(Employee xml as mentioned above).
Now I have to get the value of element in the XML stored in column DATA using Xquery (Or any other way is also fine).
I am trying the following query, but I am getting the value EmpName as NULL.
select XMLCAST(XMLQUERY('$d/Employee/EmpDetails/Name' PASSING rg.DATA AS "d") AS VARCHAR(50)) AS EmpName from REGEVENT rg where REFID='12345';