简体   繁体   中英

Compare two xml sql query DB2

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

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))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM