Reputation: 99
It's easy to replace a character one time with a function such as this:
regexp_replace(string INITIAL_STRING, string PATTERN, string REPLACEMENT)
But how to deal with multiple string replacements in a column at one time?
For example, with relation like A to @, B to #, C to Z, how would one change "ABC"
into "@#Z"
?
Upvotes: 1
Views: 1455
Reputation: 38290
Use translate(input, from, to) function, it translates the input string by replacing the characters present in the from string with the corresponding characters in the to string:
hive> select translate('initial string ABC A B C','ABC','@#Z');
OK
initial string @#Z @ # Z
Time taken: 0.063 seconds, Fetched: 1 row(s)
Upvotes: 1