String Reversal in Teradata Sql:
CREATE
CREATE
INSERT INTO Dummy_Emp VALUES(1, 'RAJGOPAL GURRAPUSHALA');
INSERT INTO Dummy_Emp VALUES(2, 'RAJGOPAL');
INSERT INTO Dummy_Emp VALUES(3, 'GURRAPUSHALA');
INSERT INTO Dummy_Emp VALUES(4, '');
WITH
RECURSIVE REVNAME(EMP_ID, EMP_NAME, NAMELEN, LVL, RNAME)
AS(SELECT EMP_ID, EMP_NAME, CHARACTER_LENGTH(EMP_NAME), 1(INTEGER), '' (VARCHAR(30))
FROM Dummy_Emp --WHERE EMP_ID=2
UNION
ALL SELECT
EMP_ID, EMP_NAME, NAMELEN, LVL+1, SUBSTRING(EMP_NAME FROM LVL FOR 1) || RNAMEFROM REVNAMEWHERE LVL <= NAMELEN
)SELECT EMP_ID, EMP_NAME, RNAMEFROM REVNAMEWHERE NAMELEN+1 = LVLORDER BY 1;
No comments:
Post a Comment