首页 > 解决方案 > Sqlite query to get list of next available characters after the matching search keyword

问题描述

How to query sqlite database to get list of next available characters after the search keyword in a string field. for example, if the search keyword is ’and’</p>

and let the strings be a list of names like :

  1. Andy Xyz
  2. Andrew Xyz
  3. Xyz Andon
  4. Xyz Miranda

then i should get the characters [y,r,o,a].

I tried the query with substr(names,1,1), but substr needs to specify the start index which will be different in each strings. Is it possible to fetch these characters using sqlite query?

标签: androidsqliteandroid-sqlite

解决方案


你需要substr()instr()

select 
substr(names, instr(lower(names), lower('and')) + length('and'), 1) nextchar 
from tablename
where 
  names like '%' || 'and' || '_%'

查看演示您可以在上述查询中
替换为您希望的任何字符串。'and'


推荐阅读