Compare two xml sql query DB2

Viewed 179

I have two tables in the database. Both have ID, name1. Name1 is an XML data type. Does anyone know of any possibility to compare the contents of these two xml?

select * from table1 t join table2 b on t.ID = b.ID where t.name1 <> b.name1

But it doesn't work. I get

SQL Error [42818]: The data types of the operands for the operation "<>" are not compatible or comparable.. SQLCODE=-401, SQLSTATE=42818, DRIVER=4.21.29

1 Answers

You can compare a VARCHAR version of the two XML values using XMLSERIALIZE:

select * 
from table1 t 
join table2 b on t.ID = b.ID 
where xmlserialize(t.name1 as varchar(32672)) 
   <> xmlserialize(b.name1 as varchar(32672))
Related