在MySQL表中有一个JSON类型。但是,如果数据值包含一个单引号,则它将失败,从而导致SQL语法错误。请查找SQL查询:
如果在单引号前添加转义字符,则可以解决此问题。但是,在MYSQL中是否有任何易于使用的JSON函数?我们必须从另一个用Java编写的应用程序中提供查询,如果可能的话,我们不想修改程序。
INSERT INTO integration.staging_correspondence_inbound_invoice (correlation_id,interface_name,event_status,event_context,created_by,created_date) values ('1540626495812-0-1','invoice','EXCEPTION_CAUGHT',JSON_ARRAY('[ {
"exceptionRootCauseMessage" : "UpdateFailedException: Unable to update correspondence for correspondence id '68000'.Exception:{null\n> Record set for Correspondence with ids 68000 contains no records.\n>> }",
"inExchangeBody" : null,
"exceptionMessage" : "UpdateFailedException: Unable to update correspondence for correspondence id '68000'.Exception:{null\n> Record set for Correspondence with ids 68000 contains no records.\n>> }"
}, { }, {
"EXCEPTION_CAUGHT" : "Unable to update correspondence for correspondence id '68000'.Exception:{null\n> Record set for Correspondence with ids 68000 contains no records.\n>> }"
} ]'),'Integration_User',NOW())我们使用的是MySQL 5.7。在上面的查询中,"event_context"是JSON类型字段。
发布于 2018-10-29 05:37:26
您可以查看MySql 报价函数。它应该能解决你的问题。根据文件:
-> Quote ->(-> str --> )->
该函数通过用单引号包围字符串,并在每个单引号、反斜杠、ASCII和control前面加上一个反斜杠来实现这一点。
发布于 2021-11-28 04:17:12
使用base64
<?php
$json = base64_encode($json);
$sql = "UPDATE `entries` e SET e.fields = FROM_BASE64('".$json."') WHERE form_id = 163 AND e.fields LIKE '%$test_id%' LIMIT 1";
?>https://stackoverflow.com/questions/53039121
复制相似问题