Search code examples
androidsqlandroid-roomandroid-architecture-components

Android Rooms - Search in String


In the Android Rooms persistence library, how would I write the following SQL statement as a @Query?

SELECT * FROM table WHERE field LIKE %:value%

This syntax is invalid, and I can't find anything about it in the documentation.


Solution

  • You can just concatenate using SQLite string concatenation.

    @Query("SELECT * FROM table WHERE field LIKE '%' || :value  || '%'")