1
This function would return the last two "95512" or to return the number without the last two digits "95512".
The value passed to function can vary, at least 3 character and at most 11
DELIMITER $$
DROP FUNCTION IF EXISTS subInteiro $$
CREATE FUNCTION subInteiro(nCOD INT, nIncio INT, nFim INT) RETURNS VARCHAR(500)
DETERMINISTIC
BEGIN
DECLARE lvl VARCHAR(500);
SET lvl = SUBSTRING(CAST(nCOD AS CHAR), nIncio, CHAR_LENGTH(CAST(nCOD AS CHAR)) - nFim ) ;
RETURN (lvl);
END $$
DELIMITER ;
I’m taking these tests
SELECT subInteiro(4518486299,-2,2); # return 47
SELECT subInteiro(201,-2,2); # return 0
In the first example it was to return 99 and in the second 01