Anup Ammanavar
Anup Ammanavar

Reputation: 432

How to concatenate string in room dao query?

I'm using a LIKE operator in my Query

 @Query("SELECT * FROM item where barcodes LIKE :barcode")
 List<Item> getItemWithBarcode(String barcode);

Is there any way that i can append something(appendedTxt) to the bar code? Like this

@Query("SELECT * FROM item where barcodes LIKE (:barcode + 'appendedTxt')")
List<Item> getItemWithBarcode(String barcode);

Upvotes: 5

Views: 2363

Answers (1)

LonelyCpp
LonelyCpp

Reputation: 2673

The || operator is "concatenate" - it joins together the two strings of its operands. Docs

@Query("SELECT * FROM item where barcodes LIKE (:barcode || 'appendedTxt')")

List<Item> getItemWithBarcode(String barcode);

edit: changed double quotes to single

Upvotes: 10

Related Questions