频道栏目
首页 > 资讯 > Oracle > 正文

使用Oracle REPLACE函数替换查询结果中的指定字符(ReplacesubstringinOracle)的调试经验分享

18-06-23        来源:[db:作者]  
收藏   我要投稿

需求:

查询出来的字段中带有一些前缀,用户不希望在报表中显示这些前缀。目前的操作方法是在Excel中手动替换掉。我在想,有没有办法自动化?使用VBA有点小题大做,能不能放到SQL中实现呢?可以,使用REPLACE函数即可。

代码:

REPLACE (UTABLE.UFIELD, 'NOT_NEEDED','')

顺便了解以下Oracle Database SQL Language Reference中对REPLACE函数的描述:

-----------------------------------------------------------------------------------------------------------------

Purpose

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.

Examples

The following example replaces occurrences of J with BL:

SELECT REPLACE('JACK and JUE','J','BL') "Changes"

FROM DUAL;

Changes

--------------

BLACK and BLUE

相关TAG标签
上一篇:原生JS结合CSS还有HTML实现页面弹框(代码教程)
下一篇:HTML中src和href的区别讲解
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站