replace函数浅析

REPLACE(char, search_string [, replacement_string ]   )


REPLACE returns char with every occurrence of search_string replaced with replacement_string. If replacement_string is omitted or null, then all occurrences of search_string are removed. If search_string is null, then char is returned.


Both search_string and replacement_string, as well as char, can be any of the data types CHAR, VARCHAR2, NCHAR, NVARCHAR2, CLOB, or NCLOB. The string returned is in the same character set as char. The function returns VARCHAR2 if the first argument is not a LOB and returns CLOB if the first argument is a LOB.


REPLACE provides functionality related to that provided by the TRANSLATE function. TRANSLATE provides single-character, one-to-one substitution. REPLACE lets you substitute one string for another as well as to remove character strings.


SCOTT@PROD2> select replace('abcabbaccbcc','a') from dual;  --如果省略replacement_string参数则移除所有search_string.


REPLACE('
---------

bcbbccbcc


--实验
--更新表将JOB结尾为MAN的为MEN。
SCOTT@PROD2> select * from t;

ENAME	   JOB
---------- ---------
SMITH	   CLERK
ALLEN	   SALESMAN
WARD	   SALESMAN
JONES	   MANAGER
MARTIN	   SALESMAN
BLAKE	   MANAGER
CLARK	   MANAGER
SCOTT	   ANALYST
KING	   PRESIDENT
TURNER	   SALESMAN
ADAMS	   CLERK
JAMES	   CLERK
FORD	   ANALYST
MILLER	   CLERK

14 rows selected.

SCOTT@PROD2> update t set job=replace(job,'MAN','MEN') where job = 'SALESMAN';

4 rows updated.

SCOTT@PROD2> select * from t;

ENAME	   JOB
---------- ---------
SMITH	   CLERK
ALLEN	   SALESMEN
WARD	   SALESMEN
JONES	   MANAGER
MARTIN	   SALESMEN
BLAKE	   MANAGER
CLARK	   MANAGER
SCOTT	   ANALYST
KING	   PRESIDENT
TURNER	   SALESMEN
ADAMS	   CLERK
JAMES	   CLERK
FORD	   ANALYST
MILLER	   CLERK

14 rows selected.
	


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值