甲骨文中的instr()函数

  

一、instr()函数的格式(俗称:字符查找函数)

  

格式一:instr (string1 string2相等)
/instr(源字符串,目标字符串)

  

格式二:instr (string1, string2相等(,start_position [, nth_appearance]])
/instr(源字符串,目标字符串,起始位置,匹配序号)

  

解析:string2相等的值要在string1中查找,是从start_position给出的数值(即:位置)开始在string1检索,检索第nth_appearance(几)次出现string2相等。

  

注:在Oracle/PLSQL中,instr函数返回要截取的字符串在源字符串中的位置。只检索一次,也就是说从字符的开始到字符的结尾就结束。

  

二、实例

  

格式一
1,选择instr (“helloworld”、“l”)双;——默认第一次出现“l”的位置
凹坠俏闹械膇nstr()函数”
2,选择instr (“helloworld”、“lo”)双;——在“lo”中,“l”开始出现的位置
凹坠俏闹械膇nstr()函数”
3,选择instr (“helloworld”,“我们”)双;——“w”开始出现的位置
凹坠俏闹械膇nstr()函数"

  

格式二
1,选择instr (“helloworld”、“l”2 2)双;
——在“helloworld"的第(e) 2号位置开始,查找第二次出现的“l”的位置
凹坠俏闹械膇nstr()函数”
2,选择instr (“helloworld”、“l”、3、2)双;
——在“helloworld"的第3(左)号位置开始,查找第二次出现的“l”的位置
凹坠俏闹械膇nstr()函数”
3,选择instr (“helloworld”、“l”、4、2)双;
——在“helloworld"的第(l) 4号位置开始,查找第二次出现的“l”的位置
凹坠俏闹械膇nstr()函数”
4,选择instr (“helloworld”、“l”, 1, 1)从双;
——在“helloworld"的倒数第(d) 1号位置开始,往回查找第一次出现的“l”的位置
凹坠俏闹械膇nstr()函数”
5,选择instr (“helloworld”、“l”, 1, 2)从双;
——在“helloworld"的倒数第(d) 1号位置开始,往回查找第二次出现的“l”的位置
凹坠俏闹械膇nstr()函数”
6,选择instr (“helloworld”、“l”, 2, 3)双;
——在“helloworld"的第(e) 2号位置开始,查找第三次出现的“l”的位置
凹坠俏闹械膇nstr()函数”
7,选择instr (“helloworld”、“l”, 2, 3)双;
——在“helloworld"的倒数第(l) 2号位置开始,往回查找第三次出现的“l”的位置
凹坠俏闹械膇nstr()函数"

  

注:模糊查询像和instr()函数有同样的查询效果:
从表中选择 colName像% helloworld %的;
从表中选择
instr (colName,“helloworld”)在0;——这两条语句的效果是一样的
例:
凹坠俏闹械膇nstr()函数”
凹坠俏闹械膇nstr()函数"

甲骨文中的instr()函数