1、使用substring_index(src,target,index) 从src的开头查找第index个target。返回的substring为从src的开头到第num个target这段字符串。比如
substring_index('absscdessfss','ss',1) 返回ab
substring_index('absscdessfss','ss',2) 返回absscde
substring_index('absscdessfss','tt',1) 返回absscdessfss
因此,检查字符串是否包含子串,使用substring_index('absscdessfss','tt',1) 看他返回是不是一个子串,是子串说明包含,返回的是原来完成的字符串,说明不包含。
length(src) - length(substring_index(src,target,1)) >0 说明包含。
2、第二种办法,把target替换为空字符串,如果存在target,则替换后的长度必定小于原来的长度
length(src) - length(replace(src,target,'')) >0 说明包含。
进一步思考,还可以计算包含几个子串,长度的差值除以target的长度,就是包含子串的个数。
select (length(src) - length(replace(src,target,'')))/length(target);

mysql 检查字符串是否包含子串的更多相关文章

  1. 如何在 JavaScript 中检查字符串是否包含子字符串?

    如何在 JavaScript 中检查字符串是否包含子字符串? // var test4 = _.includes(string, substring); 该方法需要此文件 <script src ...

  2. python删除所有的中文字符、非ASCII或非英文字符,检查字符串是否包含非ASCII

    Your ''.join() expression is filtering, removing anything non-ASCII; you could use a conditional exp ...

  3. 检查字符串是否包含另一串字符串(c++)

    在c++中检查字符串是否包含另一串字符串,这个本来是我做过的一个算法题,不过最近刚好有个需求让我想到了这个题,就在此记录一下! 使用std::string::findfunction string s ...

  4. Java检查字符串是否包含中文字符

    转自:https://blog.csdn.net/zhanghan18333611647/article/details/80038629 强烈推荐一个大神的人工智能的教程:http://www.ca ...

  5. H面试程序(11): 判断字符串是否包含子串问题

    题目描述:                        如字符串str1为''abcdef'''                       字符串str2为'' bc''; 则字符串str1中含有 ...

  6. Python判断一个字符串是否包含子串的几种方法

    转自---http://blog.csdn.net/yl2isoft/article/details/52079960 1.使用成员操作符 in >>> s='nihao,shiji ...

  7. MS SQL验证字符串是否包含有大小写字母

    昨晚有实现一个小功能,就是在MS SQL Server中,检查字符串是否包含有大小写字母.通常应用在字符串的复杂度. ) = N'SDFfgGRYJhhTYUJ' IF LOWER(@s) COLLA ...

  8. mysql判断一个字符串是否包含某子串

    使用locate(substr,str)函数,如果包含,返回>0的数,否则返回0 例子:判断site表中的url是否包含'http://'子串,如果不包含则拼接在url字符串开头 update ...

  9. mysql判断一个字符串是否包含某子串 【转】

    文章出处:mysql判断一个字符串是否包含某子串 使用locate(substr,str)函数,如果包含,返回>0的数,否则返回0 例子:判断site表中的url是否包含'http://'子串, ...

随机推荐

  1. HDU 2846:Repository(Trie)

    http://acm.hdu.edu.cn/showproblem.php?pid=2846 题意:给出N个模式串,再给出M个文本串,问每一个文本串在多少个模式串中出现. 思路:平时都是找前缀的,这里 ...

  2. WPF:MenuItem样式

    基础信息 1.MenuItem 样式 <Window.Resources> <Style TargetType="{x:Type MenuItem}"> & ...

  3. redis 几种数据类型往数据库存数据和取数据的帮助类

    package com.fndsoft.bcis.utils; import org.springframework.beans.factory.annotation.Autowired; impor ...

  4. quick lua 使用spine骨骼动画

    看下下面两个文件 <spine/SkeletonRenderer.h><spine/SkeletonAnimation.h> 1.lua中创建方法: sp.SkeletonAn ...

  5. poj1785 Binary Search Heap Construction

    此题可以先排序再用rmq递归解决. 当然可以用treap. http://poj.org/problem?id=1785 #include <cstdio> #include <cs ...

  6. U3D UGUI学习4 - Text

    1.对应NGUI的四种文字显示模式 Shrink Content 对应NGUI第一种模式     勾选Best Fit 但似乎有一个Bug,文字过多的时候会爆框.解决方法是改变Line Spacing ...

  7. EditorWindow窗口大小锁死后没有边框的解决方法

    var window = GetWindow(typeof(MyWindow), true); window.minSize = , ); window.maxSize = window.minSiz ...

  8. 放松时刻——C#分割字符串

    让我们来练习一下字符串的分割~把话倒过来说: private void change_button_Click(object sender, EventArgs e) { var after_text ...

  9. mean函数

    求平均值 th> a=torch.zeros(,) [.0002s] th> a [torch.DoubleTensor of size 1x3] [.0003s] th> a[{, ...

  10. jquery easyui datagrid使用参考

    jquery easyui datagrid使用参考   创建datagrid 在页面上添加一个div或table标签,然后用jquery获取这个标签,并初始化一个datagrid.代码如下: 页面上 ...