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
SELECTRIGHT('John Smith', 5) AS LAST_NAME;
Output:
LAST_NAME|
------------+
Smith|
Code:
OUT -> SQLServer_01.sql
SELECTRIGHT('John Smith', 5) AS LAST_NAME;
Output:
LAST_NAME|
------------+
Smith|
Code:
CREATE OR REPLACEFUNCTIONright_str(str varchar, indexfloat)RETURNS stringLANGUAGE JAVASCRIPTAS$$functionRIGHT(string, index){if(index<0){throw new RangeError('Invalid INDEX on RIGHT function'); }return string.slice( string.length -index, string.length ); }returnRIGHT(STR, INDEX);$$;SELECT RIGHT_STR('John Smith', 5) AS LAST_NAME;