What is wrong with this Mysql CREATE FUNCTION?

Asked

Viewed 33 times

1

What’s wrong with create Function? I’m not finding out. Already of the error in the first line.

CREATE FUNCTION SEQ_NEXT_VAL() 
RETURNS INT 
DETERMINISTIC
BEGIN
  DECLARE retorno INT;

  SELECT MAX(IDE_ERROR) INTO retorno FROM ERROR_LOGGING;
  IF retorno = NULL THEN
    retorno = 1;
  ELSE
    retorno = retorno + 1;
  END IF;

  RETURN retorno;
END;
  • 1

    And what was the error reported? You will have to [Edit] the question with the details in order to help.

  • ERROR 1064(42000): you have an error in SQL syntax near '' at line 5

  • 1

    lack the delimiter, do so: delimiter $$ and at the end of the function end $$

  • @Everson is not that the problem just lacked the SET of variables.

  • Note that in this other question - https://stackoverflow.com/q/6740932, the error is the same commented this, and this missing delimite, what was said in the answer accepted.

  • Note that in this question, in the question is already with the SET of variables, so DELIMITER is really missing, but as I said, depending on some editors they do it automatically

Show 1 more comment

1 answer

0

Missing set of variables:

DROP FUNCTION IF EXISTS SEQ_NEXT_VAL;
DELIMITER |
CREATE FUNCTION SEQ_NEXT_VAL() 
RETURNS INT 
DETERMINISTIC
BEGIN
  DECLARE retorno INT;

  SELECT MAX(IDE_ERROR) INTO retorno FROM ERROR_LOGGING;
  IF retorno = NULL THEN
    SET retorno = 1;
  ELSE
    SET retorno = retorno + 1;
  END IF;

  RETURN retorno;
END
|
DELIMITER ;
  • works like this, depending on the SQL edit you are using, but to put yes.

  • I’m using the same command line

  • now giving error in line 1 in the declare

  • @Bicabicudo edited with DELIMITER

  • with the $$ delimiter worked and lacked the set too

  • what you put in DELIMITER is indifferent you are only changing the Mysql delimiter at this time

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.