Section 9:94. String Manipulation – Reversing and concatenating multiple strings

In Hive, you can manipulate strings by reversing and concatenating them using built-in functions.

  1. REVERSE: The REVERSE function is used to reverse the characters in a string. The syntax for the REVERSE function is as follows

REVERSE(input_string)

For example:

SELECT REVERSE(‘Hello World’); — Returns ‘dlroW olleH’

  1. CONCAT: The CONCAT function is used to concatenate multiple strings into a single string. The syntax for the CONCAT function is as follows:

CONCAT(string1, string2, …, stringN)

For example:

SELECT CONCAT(‘Hello’, ‘ ‘, ‘World’); — Returns ‘Hello World’

You can also use the vertical bars (||) as a shorthand for the CONCAT function:

SELECT ‘Hello’ || ‘ ‘ || ‘World’; — Returns ‘Hello World’

To reverse and concatenate strings, you can use the REVERSE function together with the CONCAT function:

SELECT CONCAT(REVERSE(‘Hello’), ‘ ‘, REVERSE(‘World’)); — Returns ‘olleH dlroW’

Note that the order of the input strings affects the resulting output string.

Share this post