比如有一个a字段格式如下: aaaa-bbbb-cc 要截取最后的cc 1,首先获取最后一次出现的- 的位置 instr('aaaa-bbbb-cc','-',-1),这样就得到了最后一个-的下标 2,从最后一次出现-的位置开始截取字符串 下标加一,然后截取 substr('aaaa-bbbb-cc',instr('aaaa-bbbb-cc','-',-1)+1) 运行例子
在Mysql中,可以使用INSTR(str,substr)函数,用于在一个字符串(str)中搜索指定的字符(substr),返回找到指定的字符的第一个位置(index),index是从1开始计算,如果没有找到就直接返回0,没有返回负数的情况。其中str被搜索的字符串,substr希望搜索的字符串。 eg:
大家都知道mysql 模糊查询的常用方法是LIKE 但这个语句查询效率很慢,那么有没有比较好的方法呢,下面本人测试了几个语句 测试数据800条左右 1, 测试结果用时0.06s 2 locate()用时0.02s 3 find_in_set() 用时0.02s 4 instr instr() 用时0.03 根据本人测试 结果可能
WITH split(word, str) AS ( -- alternatively put your query here -- SELECT '', category||',' FROM categories SELECT '', 'Auto,A,1234444,dsfdd,sd,sd'||',' UNION ALL SELECT substr(str, 0, instr
ascii/chr 返回s首位字母的ASCII码 select ascii('abc') from dual --97 返回数值i的ASCII字符 select chr(97) from dual -- a initcap 将每个单词首位字母大写其它字母小写 select initcap('hello') from dual --Hello instr/instrb 返回a在abca中第1位开始第2次出现的位置 s
将下表中左边的字段修改为右边的格式 语句: select substr(列名,instr(列名,'-',-1)+1) as 别名 from 表名; instr函数(字符查找函数): 格式: 格式1:instr(源字符串,目标字符串) select instr('helloworld','l') from dual; --返回结果:3 默认第一次出现“l”的位
46、(10-4) choose two: Examine the data in the CUST_NAME column of the CUSTOMERS table. CUST_NAME Lex De Haan Renske Ladwig Jose Manuel Urman Jason Mallin You want to extract only those customer names that have three names and display the * symbol in plac