Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在MYSQL中获取JSON数组中的值的索引?_Java_Mysql_Json - Fatal编程技术网

Java 在MYSQL中获取JSON数组中的值的索引?

Java 在MYSQL中获取JSON数组中的值的索引?,java,mysql,json,Java,Mysql,Json,是否有一种方法可以通过JSON数组中值的索引进行搜索。例如,有没有一种方法可以做像 Select * FROM table WHERE myJSONArr.indexOf("s") = 3 or 4 这样它将返回JSON列“myJSONArr”中索引“s”为3或4的所有行?这可能会对您有所帮助 CREATE TABLE test_json_table ( id integer , tags json DEFAULT NULL, PRIMARY KEY (id) ); insert into

是否有一种方法可以通过JSON数组中值的索引进行搜索。例如,有没有一种方法可以做像

Select * FROM table WHERE myJSONArr.indexOf("s") = 3 or 4
这样它将返回JSON列“myJSONArr”中索引“s”为3或4的所有行?

这可能会对您有所帮助

CREATE TABLE test_json_table (
id integer ,
tags json DEFAULT NULL,
PRIMARY KEY (id)
);

insert into test_json_table VALUES (1, '["JavaScript", "ES2015", "JSON"]');
insert into test_json_table VALUES (2, '["JavaScript", "Python", "ES2015", "JSON"]');


select v1.*
from (select cast(tags as char) as tags_str from test_json_table) as v1
where POSITION("[" IN v1.tags_str) IN (1,2) ;

如果你提供更多的细节,你可能会得到更多的帮助。一些json示例和预期结果。您将json文档放在SQL数据库中的是什么,它会破坏数据库的功能(索引和查询),并且不会节省空间。如果您需要更大的灵活性,也许您应该考虑像MongoDB这样的NoSQL数据库。@nyamiouthegaleanstrope MySQL有一个json数据类型和支持它的函数,我认为在MySQL中使用json没有任何问题。特别是当他们需要一个混合的关系/非关系解决方案时。我正在浏览一些选项。我看到MYSQL提供了获取JSONArray大小的方法以及其他特性,但我没有看到任何关于元素索引的内容。