Oracle 中 translate 浅析

语法格式:translate(expr, from_string, to_string)

示例如下:

select translate('ab你好bcadefg', 'abcdefg', '1234567') as new_str
from dual;

new_str
---------------
12 你好 2314567

from_stringto_string 以字符为单位,对应字符一一替换。

对应字符
a1replace('a', '1')以字符为单位一一对应替换
b2replace('b', '2')
c3replace('c', '3')
d4replace('d', '4')
e5replace('e', '5')
f6replace('f', '6') 
g7replace('g', '7')

 

替换过程
a1 
b2 
不作
替换
b2不管字符在何位置,均替换,如a、b
c3
a1
d4 
e5 
f6 
g7 

如果 to_string 为空,则返回空值。

SQL> set null NULL
Cannot SET NULL
SQL> col new_str from a10
SQL> select translate('ab你好bcadefg', 'abcdefg', '') as new_str from dual;

NEW_STR
-------------
NULL

如果 to_string 对应的位置没有字符,则 from_string 中列出的字符将会被消掉。

select translate('ab你好bcadefg', 'labcdefg', 'l') as new_str from dual;

NEW_STR
---------
你好

 

llreplace('l', 'l')
areplace('a', '')
breplace('b', '')
creplace('c', '')
dreplace('d', '')
ereplace('e', '')
freplace('f', '')
greplace('g', '')
expr 中没有 ll

      没有忽略

a同后面
b 
 
 
b对应位置没有字符,替换为空
c
a
d
e
f
g

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

爱打斯诺克的码农飞

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值