How do I use regex in a SQLite query?

后端 未结 17 1799
暖寄归人
暖寄归人 2020-11-22 05:57

I\'d like to use a regular expression in sqlite, but I don\'t know how.

My table has got a column with strings like this: \"3,12,13,14,19,28,32\" Now if I type \"whe

17条回答
  •  南方客
    南方客 (楼主)
    2020-11-22 06:42

    An exhaustive or'ed where clause can do it without string concatenation:

    WHERE ( x == '3' OR
            x LIKE '%,3' OR
            x LIKE '3,%' OR
            x LIKE '%,3,%');
    

    Includes the four cases exact match, end of list, beginning of list, and mid list.

    This is more verbose, doesn't require the regex extension.

提交回复
热议问题