MYSQL stored function - create function (function definition) problem using FORMAT

Posted by Jason Fonseca on Stack Overflow See other posts from Stack Overflow or by Jason Fonseca
Published on 2010-03-31T01:48:45Z Indexed on 2010/03/31 1:53 UTC
Read the original article Hit count: 649

Hi all,

I keep receiving an error with the following code. I am trying to make a function that will format a field (content=0.0032) into a varchar/percent (content=0.32%). At the moment i'm just trying to get format to work, and it throws up an error

"Error Code : 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'len);"

The function definition for "Format" is "Format(X,d)" where x is the number and d is the number of decimal places to round too. It then should output a string ###,###,###.## etc.

My code is as follows:

DROP FUNCTION IF EXISTS percent;
DELIMITER $$

CREATE
    /*[DEFINER = { user | CURRENT_USER }]*/
    FUNCTION `auau7859_aba`.`percent`(num DOUBLE, len INT)
    RETURNS VARCHAR(10)
    DETERMINISTIC

    BEGIN
    RETURN FORMAT(num,len);
    END$$

DELIMITER ;

Save me...Luke

© Stack Overflow or respective owner

Related posts about mysql

Related posts about stored-functions