I have this xml on my db:
<requestXML>
<headers>
<name>Accept</name>
<value>text/plain, application/json, application/*+json, */*</value>
</headers>
<method>PUT</method>
<payload>{"timestamp":"1659167441820","orderIdentifierCode":"OC22004795","clientName":"XXXX","country":"XX","vatNumber":"XXXXXXXX","orderDate":"XX/XX/XXXX","orderState":"XX"}</payload>
<threadName>default task-xx</threadName>
<url>http://localhost:8080/service_name</url>
</requestXML>
I tried to perform a SELECT statement with XMLExists but with no results.
What I need is to search into <payload> tag, inside those json body, the orderIdentifierCode value.
Here my SELECT:
SELECT * FROM EVDA.TETSIR_LOG_WS_PBE
AS X
WHERE XMLExists('$XML//requestXML/payload[orderIdentifierCode="OC22004795"]' passing X.T_RIC_XML AS "XML")
AND D_TMS_REG BETWEEN '2022-07-27 00:00:00.000001' AND '2022-08-02 23:59:59.999999'
WITH UR;
This one, on the contrary, is working fine:
SELECT * FROM EVDA.TETSIR_LOG_WS_PBE
AS X
WHERE XMLExists('$XML//requestXML[method="PUT"]' passing X.T_RIC_XML AS "XML")
AND D_TMS_REG BETWEEN '2022-07-27 00:00:00.000001' AND '2022-08-02 23:59:59.999999'
WITH UR;
I started to think that the first one is not well formatted or that something is missing due to complex value inside the tag <payload>.
Any guess?
Thanks in advance
You have to get the JSON value first and use it afterwards.
Run the statements below depending on the database codepage as is.
UTF-8 databases only
All database encodings
You have to use older SYSTOOLS.JSON2BSON function in a non-unicode database.
The preferable way is not to use SYSTOOLS JSON functions. So, if you have UTF-8 database, it's better to use the above statement.
Seems, that SYSIBM.JSON_TABLE doesn't work in non-unicode databases.