functionRIGHT(string, index){if(index<0){thrownewRangeError('Invalid INDEX on RIGHT function'); }returnstring.slice( string.length- index,string.length ); }
Examples
Code:
IN -> SQLServer_01.sql
SELECT RIGHT('John Smith', 5) AS LAST_NAME;
Output:
LAST_NAME|
------------+
Smith|
Code:
OUT -> SQLServer_01.sql
SELECT RIGHT('John Smith', 5) AS LAST_NAME;
Output:
LAST_NAME|
------------+
Smith|
Code:
CREATE OR REPLACE FUNCTION right_str(str varchar, indexfloat) RETURNS string LANGUAGE JAVASCRIPTAS$$function RIGHT(string, index){if(index<0){throw new RangeError('Invalid INDEX on RIGHT function'); }return string.slice( string.length -index, string.length ); }return RIGHT(STR, INDEX);$$;SELECT RIGHT_STR('John Smith', 5) AS LAST_NAME;