比如字符串‘abcdefg’中,将第三位‘c'替换为’m',oracle中如何写?

解决方案 »

  1.   

    SELECT SUBSTR('abcdefg',1,2)||'m'||SUBSTR('abcdefg',4) FROM DUAL;
      

  2.   

    update test set a=substr(a,1,2)||'m'||substr(a,3, length(a)-3) where length(a)>=3 and substr(a,3,1)='c'这个应该可以。
      

  3.   

    用oracle的内置函数:replace
    select replace('abcdefg','c','m'  ) from dual;
      

  4.   

    这样就可以了select replace ('abcdefg',substr('abcdefg',3,1),'m') from dual;
      

  5.   

    奥,我错了,下面的话也是很笨的方法哈。
    select replace (substr('abcdefg',1,3),substr('abcdefg',3,1),'m')||substr('abcdefg',4) from dual;
      

  6.   

    --将第3位替换成字符c
    select regexp_replace('abxdef','(.){1}(.){1}(.){1}(.*)','\1\2c\4') from dual;
      

  7.   

    --将第3位替换成字符c,这个也可以
    select regexp_replace('abxdef','(..)(.)(.*)','\1c\3') from dual;
      

  8.   

    --这个更好,将第3个参数查找位置指定成要替换的位置减1就行了
    select regexp_replace('abxdef','(.){1}(.)(.*)','\1c\3',2) from dual;