android sqlite 'like' 查询和取模表达式

android sqlite 'like' query and modulo expression

当我在 android sql 中使用 LIKE 查询时,我想 'contains' 查询一些输入。

db.query(TABLE,
         new String[]{COLUMN},
         CONDITIONS + " LIKE " + "?",
         new String[]{("%" + input + "%")},
         null
         null
         ORDER_COLUMN + " DESC",
         null);

查询运行良好,但是当我在输入中使用“%”字符时,它像空字符串一样工作。

我想使用像普通字符串一样的 '%' 字符。

我该怎么办..?

谢谢。

使用 LIKE y ESCAPE z 形式为 LIKE 表达式指定一个转义字符,然后使用该转义字符为 LIKE 表达式中需要按字面意义理解的任何 % 添加前缀。例如:

sqlite> create table t(a);
sqlite> insert into t values('a%b');
sqlite> insert into t values('ab');
sqlite> insert into t values('aa%bb');
sqlite> select * from t where a like '%a\%b%' escape '\';
a%b
aa%bb