IBM Support

75 ways to demystify DB2 #59: Techtip : How to find out the length of a XML data?

Technical Blog Post


Abstract

75 ways to demystify DB2 #59: Techtip : How to find out the length of a XML data?

Body

Are you trying find out length of XML data ?


Here is the example:
 

create table tab1(c1 int, c2 xml)
DB20000I  The SQL command completed successfully.

 

insert into tab1 values (2,'<ABC>123</ABC>')
DB20000I  The SQL command completed successfully.

 

insert into tab1 values (1,'<ABC>1234</ABC>')
DB20000I  The SQL command completed successfully.

 

select length(xmlserialize(c2 as clob(20m))) as xml_length from tab1
XML_LENGTH
-----------
         14
         15

  2 record(s) selected.

[{"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Product":{"code":"SSEPGG","label":"Db2 for Linux, UNIX and Windows"},"Component":"","Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"","Edition":"","Line of Business":{"code":"LOB10","label":"Data and AI"}}]

UID

ibm11140940