Skip to main content

function which reverse a given word


abhishek_1
Forum|alt.badge.img+1
Is there any function in vertica which reverse a word? E.g: "vertica" becomes "acitrev"

3 replies

Navin_C
Forum|alt.badge.img+2
  • Participating Frequently
  • July 16, 2013
Hello Abhishek, For your requirement, I suggest you go with creating a UDx ( user defined extension ) for Reverse String For the above scenario we can do it like this create function reverse(x varchar) return varchar as begin return (substr(x, 10, 1 ) || substr(x, 9, 1 ) || substr(x, 8, 1 ) || substr(x, 7, 1 ) || substr(x, 6, 1 ) || substr(x, 5, 1 ) || substr(x, 4, 1 ) || substr(x, 3, 1 ) || substr(x, 2, 1 ) || substr(x, 1, 1 )); end; CREATE FUNCTION nnani=> select reverse('Vertica') from dual; reverse --------- acitreV (1 row) This Function is limited to 10 Characters word.

abhishek_1
Forum|alt.badge.img+1
  • Author
  • Participating Frequently
  • July 16, 2013
Thanks Navin !! Actually I was eager to know whether there is any "reverse" function as we have in oracle. It seems the answer is "No". We will have to make a UDx

Forum|alt.badge.img+2
  • Participating Frequently
  • July 16, 2013
If you do write a UDx, you're more than welcome to submit it to Vertica's CompatLib package (which contains other UDx's based on Oracle functions, but not reverse()): https://github.com/vertica/Vertica-Extension-Packages/tree/master/compatlib_functions