Need help in filtering bad xml data from the column which is blob format. Using the below query to achieve this and facing the below error.
Query: SELECT COLUMN1 AS NAME, CASE WHEN COLUMN2 = '' THEN XMLCAST( XMLQUERY( '$file/*:value' PASSING XMLPARSE( DOCUMENT TABLE."DATA" ) AS "file" ) AS VARCHAR(10)) ELSE COLUMN2 END AS INFO FROM TABLE
Error: [Code: -16110, SQL State: 2200M] XML syntax error. Expected to find "Comment or PI".. SQLCODE=-16110, SQLSTATE=2200M, DRIVER=4.22.29
There is no "safe" XMLPARSE function in Db2, but you may create it.
--#SET TERMINATOR @
-- Returns NULL on bad document
CREATE FUNCTION XMLPARSE_SAFE (P_DOC CLOB (1M))
RETURNS XML
CONTAINS SQL
DETERMINISTIC
NO EXTERNAL ACTION
BEGIN
DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN END;
RETURN XMLPARSE (DOCUMENT P_DOC);
END@
-- Usage
SELECT S, XMLPARSE_SAFE (S) AS DOC
FROM
(
VALUES
'<value>Not Eligible</value>'
, '<value>Not Eligible</alue>'
) T (S)@
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.