「MySQL 8.0.29」JSON_CONTAINSで指定値を含むか判定サンプル

環境
Ubuntu 22.04 LTS
MySQL 8.0.29-0ubuntu0.22.04.2

書式
JSON_CONTAINS(target, candidate[, path])
JSON_CONTAINS関数を利用して指定値を含むかどうか判定します。

SQL構文
SELECT `col`, JSON_CONTAINS(`col`, '1’, '$.flg’) FROM `json_userstbl`;

実行結果

mysql> SELECT `col`, JSON_CONTAINS(`col`, '1', '$.flg') FROM `json_userstbl`;
+-------------------------------------------------------------------------------+------------------------------------+
| col                                                                           | JSON_CONTAINS(`col`, '1', '$.flg') |
+-------------------------------------------------------------------------------+------------------------------------+
| {"flg": 1, "name": "user11", "options": {"x": 150, "y": 250}}                 |                                  1 |
| {"flg": 0, "name": "user22", "options": {"x": 300}}                           |                                  0 |
| {"flg": 1, "name": "user33", "options": {"x": 150, "y": 200, "z": [2, 3, 4]}} |                                  1 |
+-------------------------------------------------------------------------------+------------------------------------+
3 rows in set (0.02 sec)

 

MySQL

Posted by arkgame