SQL进阶--3__如何用hiveSQL删除字符串中多余的字符【详解TRANSLATE()函数】

translate()函数详解

0-需求

删除某个字段中不需要的字符,如某字段为字符串,我需要删除字符串中所有的元音字符,怎么删除?

这里举例:给出样例字符串"ABCDEFGHIOUUFEBCAADDEEII",我需要删除该字符串中的元音字符,也就是出现在该字段中包含"AEIOU"任意一个字符都需要删除掉。

1-数据分析

该需求的难点是需要去匹配"AEIOU"中的每一个字符,匹配出来后再进行删除,而每一个字符串中却包含了元音字符的任意组合,呈现出一定的无规律性,感觉无从下手,面对这种无规律性,存在随机组合的匹配模式的删除,我们采用数据库中提供的字符替换函数translate()函数。

translate()函数用法如下:

hive> desc function extended translate;
OK
translate(input, from, to) - translates the input string by replacing the characters present in the from string with the corresponding characters in the to string
translate(string input, string from, string to) is an equivalent function to translate in PostGreSQL. It works on a character by character basis on the input string (first parameter). A character in the input is checked for presence in the from string (second parameter). If a match happens, the character from to string (third parameter) which appears at the same index as the character in from string is obtained. This character is emitted in the output string  instead of the original character from the input string. If the to string is shorter than the from string, there may not be a character present at the same index in the to string. In such a case, nothing is emitted for the original character and it's deleted from the ou
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值