functionLEFT(string, index){if(index <0){thrownewRangeError('Invalid INDEX on LEFT function'); }returnstring.slice( 0, index); }returnLEFT(STR,INDEX);
Examples
Code:
IN -> SQLServer_01.sql
SELECTLEFT('John Smith', 5) AS FIRST_NAME;
Output:
FIRST_NAME|
----------+
John |
Code:
OUT -> SQLServer_01.sql
SELECTLEFT('John Smith', 5) AS FIRST_NAME;
Output:
FIRST_NAME|
----------+
John |
Code:
CREATE OR REPLACEFUNCTIONleft_str(str varchar, indexfloat)RETURNS stringLANGUAGE JAVASCRIPTAS$$functionLEFT(string, index){if(index<0){throw new RangeError('Invalid INDEX on LEFT function'); }return string.slice( 0, index); }returnLEFT(STR, INDEX);$$;SELECT LEFT_STR('John Smith', 5) AS FIRST_NAME;