Reversing the data in the column

Database
Enthusiast

Reversing the data in the column

Can u help in altering this oracle query into teradata query

update table_name set column_name=reverse(column_name)
3 REPLIES
Senior Apprentice

Re: Reversing the data in the column

There's no built-in reverse function but this should be easily written as a UDF.

Dieter
Enthusiast

Re: Reversing the data in the column

Oh, that fine

Can u help me in altering this query,so that i can update the table with reversed value

WITH RECURSIVE REVNAME(b, a, NAMELEN, LVL, RNAME)
AS
(
SELECT b, a, CHARACTER_LENGTH(a), 1(INTEGER), '' (VARCHAR(30))
FROM financial.test_data_gen

UNION ALL

SELECT b, a, NAMELEN, LVL+1, SUBSTRING(a FROM LVL FOR 1) || RNAME
FROM REVNAME
WHERE LVL <= NAMELEN
)
UPDATE financial.test_data_gen from (select rname FROM REVNAME
WHERE NAMELEN+1 = LVL) set a=REVNAME.rname where financial.test_data_gen.b=REVNAME.b ;
Senior Apprentice

Re: Reversing the data in the column

WITH RECURSIVE is only allowed in SELECTs.
You can probably create a recursive view based on your select and use that in your UPDATE.

But if it's only varchar(30) i'd use brute force:
SUBSTR(RNAME, 30,1) ||
SUBSTR(RNAME, 29,1) ||
...
SUBSTR(RNAME, 2,1) ||
SUBSTR(RNAME, 1,1)

This is much more efficient than recursion.

Dieter