1)substr函数格式 (俗称:字符截取函数)
格式1: substr(string string, int a, int b);
格式2:substr(string string, int a) ;
解释:
格式1
1、string 需要截取的字符串
2、a 截取字符串的开始位置(注:当a等于0或1时,都是从第一位开始截取)
3、b 要截取的字符串的长度
格式2
1、string 需要截取的字符串
2、a 可以理解为从第a个字符开始截取后面所有的字符串。
2)instr()函数的格式 (俗称:字符查找函数)
格式一:instr( string1, string2 ) / instr(源字符串, 目标字符串)
格式二:instr( string1, string2 [, start_position [, nth_appearance ] ] ) / instr(源字符串, 目标字符串, 起始位置, 匹配序号)
解析:string2 的值要在string1中查找,是从start_position给出的数值(即:位置)开始在string1检索,检索第nth_appearance(几)次出现string2。
注:在Oracle/PLSQL中,instr函数返回要截取的字符串在源字符串中的位置。只检索一次,也就是说从字符的开始到字符的结尾就结束。
注:MySQL中的模糊查询 like 和oracle中的instr()函数有同样的查询效果; 如下所示:
select * from tableName a where name like '%helloworld%';
select * from tableName a where instr(name,'helloworld')>0; --这两条语句的效果是一样的
数据量较大时在必须使用like时建议oracle用instr代替not like;
Oracle中的substr()函数和instr()函数使用
猜你喜欢
转载自1060064054.iteye.com/blog/2422247
今日推荐
周排行