SQLite3中子字符串的索引? [英] Index of substring in SQLite3?

查看:19
本文介绍了SQLite3中子字符串的索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 varchar 列中查找子字符串索引的最直接方法是什么?charindex 在 SQLite3 的股票版本中不存在——这对我来说仍然有点令人惊讶.

What's the most straightforward way of finidng the index of a substring in a varchar column? charindex doesn't exist in the stock version of SQLite3 -- which is still a little surprising to me.

具体来说,我有一列包含 010000011000010110 等值.我想找到第一个的索引11 的出现.对于我给出的例子,我希望像 NULL(或 -1)、13.

Specifically, I have a column with values like 010000, 011000, 010110, etc. I want to find the index of the first occurence of 11. For the examples I gave, I would expect something like NULL (or -1), 1, and 3.

我有一个结合使用 lengthltrim 的想法,但对于我需要多次执行的操作,这似乎需要做很多工作.

I have a hacked together idea that uses length and ltrim, but it seems like a lot of work for something I need to do several times.

推荐答案

很遗憾,我认为您已经找到了目前唯一有效的答案.SQLite 没有 charindex 等效函数.你可以自己制作长度和修剪,但没有内置:(

Unfortunately, I think you've found the only answer that currently works. SQLite does not have a charindex equivalent function. You an make your own with length and trim, but nothing is built in:(

这篇关于SQLite3中子字符串的索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆