一、创建测试表test_table
DROP TABLE IF EXISTS `test_table`;
CREATE TABLE `test_table` (
`ID_` varchar(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`NAME_` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL,
`META_INFO_` varchar(4000) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL,
PRIMARY KEY (`ID_`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_bin ROW_FORMAT = Dynamic;
INSERT INTO `test_table` VALUES ('188a04b0-f7df-11ee-b70d-6c0b84a4f916', '研发部请假流程', '{\"createUserId\":\"admin\",\"createUserName\":\"超级管理员\",\"description\":\"研发部请假流程\",\"updateUserId\":\"admin\",\"updateUserName\":\"超级管理员\"}');
INSERT INTO `test_table` VALUES ('28406342-f7df-11ee-b70d-6c0b84a4f916', '多实例', '{\"createUserId\":\"admin\",\"createUserName\":\"超级管理员\",\"description\":\"多实例测试\",\"updateUserId\":\"admin\",\"updateUserName\":\"超级管理员\"}');
INSERT INTO `test_table` VALUES ('748c0dde-f7de-11ee-b70d-6c0b84a4f916', '应急抢修', '{\"createUserId\":\"admin\",\"createUserName\":\"超级管理员\",\"description\":\"应急抢修工单流程\",\"updateUserId\":\"admin\",\"updateUserName\":\"超级管理员\"}');
二、查询测试表数据
select tab.* from test_table tab;
三、操作示例
- 查询json字段里的createUserName
select tab.META_INFO_ -> '$.createUserName' from test_table tab;
- 查询条件按json字段里的createUserId='admin'筛选数据
select tab.* from test_table tab where JSON_EXTRACT(tab.META_INFO_, '$.createUserId')='admin';
- 其他操作示例
3.1、JSON_OBJECT
函数用于创建一个JSON对象3.2、JSON_ARRAY
函数用于创建一个JSON数组