0

当我以这种方式进行查询时

String where = "_id in(select phrase_id from words where word like '%FIRST%' intersect select phrase_id from words where word like '%SECOND%')";
Cursor cursor = database.query(PHRASES_TABLE, columns, where, null, null, null, null);

它工作正常。但是当我尝试使用 selectionArgs 而不是硬编码值时


String where = "_id in(select phrase_id from words where word like '%?%' intersect select phrase_id from words where word like '%?%')";
String[] args = {"FIRST", "SECOND"};
Cursor cursor = database.query(PHRASES_TABLE, columns, where, args, null, null, null);

我抓住

android.database.sqlite.SQLiteBindOrColumnIndexOutOfRangeException: bind or column index out of range: handle 0x10b71e0
谢谢。

4

1 回答 1

4

?占位符不能在字符串文字中,但您可以使用 SQL 字符串连接与文字||结合:?%

String where = "_id in(select phrase_id from words where word like '%' || ? || '%' intersect select phrase_id from words where word like '%' || ? || '%')";
于 2013-10-21T10:45:21.720 回答