Search code examples
mysqlmysql-error-1064sql-function

MySQL Create function returns error


I am trying to create a function that returns rowcount. But it returns error again and again.

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 '' at line 11

DELIMITER $$
CREATE FUNCTION func1(userid INT)
RETURNS INT
NOT DETERMINISTIC
BEGIN
  DECLARE var_name INT;
  SET var_name = 0;
  SELECT COUNT(*) INTO var_name
    FROM wps_bal
    WHERE u_id = userid;
  RETURN var_name;
END$$

Solution

  • Yes. This was helpfull

    I have created the solution:

    DELIMITER $$
    CREATE FUNCTION func1(userid INT)
    RETURNS INT
    NOT DETERMINISTIC
    BEGIN
      DECLARE var_name INT;
      SET var_name = 0;
      SELECT COUNT(*) INTO var_name
        FROM wps_bal
        WHERE u_id = userid;
      RETURN var_name;
    END$$
    DELIMITER ;