views:

37

answers:

1
DELIMITER $$;
DROP FUNCTION IF EXISTS tonumeric $$;
CREATE FUNCTION tonumeric() returns numeric
BEGIN
    declare num numeric;
    set num = to_number('12');
    return num;
END$$
DELIMITER; $$

When I executed this function, I am facing this 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 'IF EXISTS tonumeric' at line 1 (0 ms taken)

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 '; CREATE FUNCTION tonumeric() returns numeric BEGIN declare num numeric; set num' at line 1 (0 ms taken)

Thanks

+2  A: 

How about this:

DELIMITER $$
DROP FUNCTION IF EXISTS tonumeric $$
CREATE FUNCTION tonumeric() returns numeric
BEGIN
    declare num numeric;
    set num = to_number('12');
    return num;
END$$
DELIMITER ;

Delimiter is a special command, in that you shouldn't terminate it with a ; -- you're actually setting the delimiter to "$$;", not "$$".

Rytmis
bah - too fast for me +1
iAn