1

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"?

1
  • One way is to use nested regexp_replace(regexp_replace(...),...) for each pattern. Commented Jul 15, 2019 at 5:22

1 Answer 1

1

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.