我在 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类型字段。
最佳答案
你可以看看MySql Quote功能。它应该可以解决您的问题。 根据文档:
--> 引用 --> ( --> str --> ) -->
The function achieves this by enclosing the string with single quotes, and by preceding each single quote, backslash, ASCII NUL and control-Z with a backslash.
关于mysql - JSON 字符串 - 在 MySQL 数据库中包含单引号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53039121/