Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);
like image 887
Anup Ammanavar Avatar asked Jan 02 '23 19:01

Anup Ammanavar


1 Answers

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

like image 97
LonelyCpp Avatar answered Jan 23 '23 20:01

LonelyCpp