本文共 988 字,大约阅读时间需要 3 分钟。
1.substr():从给定的字符表达式中返回一个子字符串。
格式:substr(string,start_position[,nChar])
注:start_position:开始截取的字符串的位置。nChar返回的字符数目。如start_position为负,则表示从右开始第start_position开始进行截取。
如select substr('absdefg',1,3) sub from dual;--abs
select substr('absdefg',5) sub from dual;--efg
select substr('absdefg',-2) sub from dual;--fg
2.like:用正则表达式进行搜索。
3.instr():对某个字符进行判断,判断其是否含有某个字符。即在一个字符中查找指定字符,返回指定字符的位置。
格式一:instr(string1,string2)
若instr(string1,string2)放在where后,那么可以作为条件查询
instr(remark,'应用')>0 相当于 remark like ‘%应用%’
instr(remark,'应用')=1 相当于 remark like ‘应用%’
instr(remark,'应用')=0 相当于 remark not like ‘%应用%’
注:
select id, name from tableses where instr('12,25', id) > 0;
它等价于 select id, name from tableses where id = 12 or id = 25;格式二:instr(string1,string2[,start_position[,nth_appearance]])
即instr(源字符串,目标字符串,开始位置,第几次出现)
注:若start_position为负值,则表示从右往左进行查找,但位置数据仍然从左向右开始进行计算。
如select instr('aasewefaaeer','aa', -1, 2) position from dual;--1
select instr('aasdfaasewefaaeer','aa', -1, 1) position from dual;--13
转载地址:http://worbn.baihongyu.com/