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
SELECT LEFT('John Smith', 5) AS FIRST_NAME;
Output:
FIRST_NAME|
----------+
John |
Code:
OUT -> SQLServer_01.sql
SELECT LEFT('John Smith', 5) AS FIRST_NAME;
Output:
FIRST_NAME|
----------+
John |
Code:
CREATE OR REPLACE FUNCTION left_str(str varchar, indexfloat)RETURNS stringLANGUAGE JAVASCRIPTAS$$function LEFT(string, index){if(index<0){throw new RangeError('Invalid INDEX on LEFT function'); }return string.slice( 0, index); }return LEFT(STR, INDEX);$$;SELECT LEFT_STR('John Smith', 5) AS FIRST_NAME;