简要比较:
replace 字符串级别的代替
如:SELECT REPLACE('accd','cd','ef') from dual; --> aefd
translate 字符级别的代替
如:select translate('acdd','cd','ef') from dual; -->aeff
replace('将要更改的字符串','被替换掉的字符串','替换字符串')
例:select replace ('111222333444','222','888') from dual;
输出为 '111888333444'
分别详解
replace:
语法:REPLACE(char,search_string[,replacement_string])
解释:replace中,每个search_string都被replacement_string所代替
select replace('acdd','cd','ef') from dual; --> aefd
如果replacement_string为空或为null,那么所有的search_string都被移除
select replace('acdd','cd','') from dual; --> ad
如果search_string 为null,那么就返回原来的char
select replace('acdd','ef') from dual; -->acdd
select replace('acdd','','') from dual; -->acdd(也是两者都为空的情况)
translate:
语法:TRANSLATE('char','from_string','to_string')
解释:translate中,每个from_string中的字符被to_string中
举例说明:
select translate('asd12fg','12','55') from dual