#JSON_EXISTS

json_exists
JSON_EXISTS ( json_value , json_path )

JSON_EXISTS函数基于json_path所描述的路径对json_value进行查找,若对应查询结果不为空则返回TRUE,否则返回FALSE。

json_value

json_value为一个二进制json数据,可通过JSON函数获取。当json_value为NULL时,函数返回NULL。

json_path

路径表达式,为一个常量字符串,其格式定义请参考json文档中描述。

示例

CREATE TABLE IF NOT EXISTS table_json (id INT, c1 VARCHAR(300));
INSERT INTO table_json VALUES(0, '{"key1": 123, "key2": true, "key3": null, "key4": [456, false, null, {"key1": true, "key2": 789, "key3": {"key6": 123}}, [10, false, null]], "key5": {"key1": true, "key2": 789, "key3": null}}');

SELECT JSON_EXISTS(JSON(c1), '$') res FROM table_json ORDER BY id;
RES 
-------------------- 
true   

SELECT JSON_EXISTS(JSON(c1), '$.key1') res FROM table_json ORDER BY id;
RES 
-------------------- 
true    

SELECT JSON_EXISTS(JSON(c1), '$.key4[10]') res FROM table_json ORDER BY id;
RES 
-------------------- 
false 
pdf-btn 下载文档
copy-btn 复制链接