例如在表格中:
create table test (id int primary key, tags json);
insert into test (id, tags) values (1, '["Lorem ipsum", "dolor", "sit"]'), (2, '["foo", "bar"]');这将匹配:
select id from test where json_search(tags, 'one', 'Lorem%') is not null但这不会:
select id from test where json_search(tags, 'one', 'lorem%') is not null理想情况下,我希望能匹配这两种情况。
运行在5.7.16 Percona XtraDB集群上
发布于 2017-02-25 03:17:52
另一种情况是,当您无法更改数据并且必须具有适当的结果时:
select
id
from test
where json_search(UPPER(tags), 'one', UPPER('lorem%')) is not null当然比较慢,所以需要对实际数据大小进行测试。
发布于 2020-09-22 10:24:14
此问题与搜索值不是_ci字符集有关。Json_search()允许不区分大小写的搜索,只要datatable的排序规则是_ci,搜索参数也是_ci。
要使用预准备语句在存储过程中解决此问题,我必须执行以下操作
SET @theQuery = "select *
from `theTable`
where
json_search(
`theTable`.`myJsonColumn`,
'all',
CONVERT( ? USING utf8) COLLATE utf8_unicode_ci,
NULL,
'$.KeyName'
) IS NOT NULL";
prepare stmt from @theQuery;
execute stmt using @searchValue;
deallocate prepare stmt;如果您需要了解有关json_search中参数的更多信息,请参见json_Search文档中的说明。
注意到?在Select内部,是使用@searchValue param编写的非参数语句。
这比执行key ()或do ()转换更有效,而且正如我注意到的,如果您确实使用了key()或lower(),则不能指定搜索键。
发布于 2017-02-24 18:23:26
这可能是由于表或字段使用的排序规则造成的。如果它是大小写敏感的,那么"l“将与"L”不匹配。为了了解校对,请运行以下命令:
SHOW CREATE TABLE test
不区分大小写的排序规则名称以"_ci“结尾。单击此处获取有关排序规则的更多信息。。
https://dba.stackexchange.com/questions/165447
复制相似问题