猿问

我怎样才能得到句子中的确切单词

如果我执行此查询,我将搜索包含以下内容的字段:

[水,可乐,7up]

[可乐、水、7up]

所以,即使参数是用大写字母写的,我也想返回这些项目,为此我正在使用这个@Query

@Query("SELECT * from drinksList WHERE list LIKE '%'||:name||'%'")

我错过了什么?

编辑

现在我正在使用LIKE %param%,但问题是如果表格是这样的:

[水,可乐,7up]

[可乐、waterera、7up]

[Waterg3d,可乐,7up]

[可乐、水23、7up]

我想找到“水”,它会显示所有这些记录,我只想找到“水”这个词,不管它是小写还是大写。


陪伴而非守候
浏览 122回答 1
1回答

慕姐8265434

以下应该有效:-@Query("SELECT * from drinksList WHERE list||',' LIKE '%'||:name||',%' OR list||',' LIKE :name||',%'")这基于/使用以下方法进行了测试:-DROP TABLE IF EXISTS DrinksList;CREATE TABLE IF NOT EXISTS DrinksList (list TEXT UNIQUE NOT NULL);INSERT INTO DrinksList VALUES&nbsp; &nbsp; ('Water, spicy, coke'),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- Should be found when searching for water&nbsp; &nbsp; ('Coke'),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- will not be found when seraching for water&nbsp; &nbsp; ('Spicy, water, coke'),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- Should be found&nbsp; &nbsp; ('Coke, spicy, water'),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- Should be found&nbsp; &nbsp; ('wateria, spicyer, cokeer'),&nbsp; &nbsp; &nbsp; &nbsp;-- should not be found&nbsp; &nbsp; ('Water, coke, 7up'),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- should be found&nbsp; &nbsp; ('Coke, waterera, 7up'),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- should not be found&nbsp; &nbsp; ('Waterg3d, coke, 7up'),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- should not be found&nbsp; &nbsp; ('Coke, water23, 7up')&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- should not be found&nbsp; &nbsp; ;SELECT * from drinkslist WHERE list||',' LIKE '%'||'water'||',%' OR list||',' LIKE 'water'||',%';导致 :-以上已经过测试,它确实在房间里工作:-所有列表显示:-在编辑文本中输入wAtER并单击“选择”按钮会导致:-进入7Up&nbsp;:-等等。查询是:-@Query("SELECT * FROM DrinkList WHERE list||',' LIKE '%'||:name||',%' OR list||',' LIKE :name||',%'")List<DrinkList> getSelectiveDrinks(String name);
随时随地看视频慕课网APP

相关分类

Java
我要回答