select instr('312','1',1) a, 
       instr('312','1',2) b,  
       instr('312','1',3) c from dual;
b=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
      

  2.   

    instr('312','1',2) b,  返回查找第2个字符的位置
    instr('312','1',3) c from dual; 返回查找第1个字符的位置
      

  3.   

    instr(result binary_integer,str1 in varchar2,str2 in varchar2,pos in binary_integer,nth in binary_integer);
    在str1里面从第pos位置到第nth位置开始查找str2,返回第一个出现str2的位置(整个str1中得位置)
      

  4.   


    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
    instr('312','1',3) 表示字符串'312'从第3个字符开始查找字符'1'的位置 这里返回的是0(从第三个字符开始找不到字符'1'了)
      

  5.   

    上面说错了,b应该是返回2
    这个函数还有第4个参数表示第N次出现这个字符的位置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
      

  6.   

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

  7.   


    如果你真的在 oracle上跑一下这个 sql ,就会发现结果不是 2 1 0 而是 2 2 0因为即使是从第二位开始查找, ‘1’的位置也是从字符串的首位开始计算的