日期:2014-05-16  浏览次数:20867 次

instr('312','1',2) 的结果解释
select instr('312','1',1) a, 
  instr('312','1',2) b,  
  instr('312','1',3) c from dual;
b=2 ?

------解决方案--------------------
1和2(第三个参数)是指 开始查找的位置 也就是说1是从312的3开始找 2就是从312的1开始找
当然 都能找到‘1’这个字符 结果都是2

但是你从312的2开始找 就找不到“1”这个字符了
------解决方案--------------------
position is an nonzero integer indicating the character of string where Oracle begins the search. If position is negative, then Oracle counts and searches backward from the end of string. 


第三个参数就是position
------解决方案--------------------
instr('312','1',2) b, 返回查找第2个字符的位置
instr('312','1',3) c from dual; 返回查找第1个字符的位置


------解决方案--------------------
第一个参数是要操作的数据,第二个参数是要找的数据,第三个参数从第几位开始找
------解决方案--------------------
查manual去。。
------解决方案--------------------
instr(result binary_integer,str1 in varchar2,str2 in varchar2,pos in binary_integer,nth in binary_integer);
在str1里面从第pos位置到第nth位置开始查找str2,返回第一个出现str2的位置(整个str1中得位置)
------解决方案--------------------
探讨
1和2(第三个参数)是指 开始查找的位置 也就是说1是从312的3开始找 2就是从312的1开始找
当然 都能找到‘1’这个字符 结果都是2

但是你从312的2开始找 就找不到“1”这个字符了

------解决方案--------------------
探讨

1和2(第三个参数)是指 开始查找的位置 也就是说1是从312的3开始找 2就是从312的1开始找
当然 都能找到‘1’这个字符 结果都是2

但是你从312的2开始找 就找不到“1”这个字符了

------解决方案--------------------
上面说错了,b应该是返回2
这个函数还有第4个参数表示第N次出现这个字符的位置
SQL code

select instr('a-b-c-d-e','-',1,1) a,  
  instr('a-b-c-d-e','-',2,2) b,   
  instr('a-b-c-d-e','-',3,3) c from dual;

------------------------
a   b   c
2   4   8

------解决方案--------------------
实测结果:


解释:
instr(参数1,参数2,参数3,参数4)
参数1:源字符串
参数2:要查找的字符串
参数3:从第几个字符开始查找(字符串中第1个字符的位置是1)
参数4:要查找字符串第几次出现。
------解决方案--------------------
探讨

实测结果:


解释:
instr(参数1,参数2,参数3,参数4)
参数1:源字符串
参数2:要查找的字符串
参数3:从第几个字符开始查找(字符串中第1个字符的位置是1)
参数4:要查找字符串第几次出现。

------解决方案--------------------
探讨

SQL code

select instr('312','1',1) a,
instr('312','1',2) b,
instr('312','1',3) c from dual;

-------------
a b c
2 1 0



instr('312','1',2) 表示字符串'312'从第2个字符开始查找字符'1'的位置 这里返回的是1
i……