chris
chris

Reputation: 565

Error on Creating Stored Function in MySQL 5.0.5

I'm usually working with mssql or postgres, but I need to use MySql in the current project. Now I have a problem with creating a stored function in MySQL 5.0.5. I'm getting the following error:

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 4

My Code looks like that:

CREATE FUNCTION aip_sf_choice_valid (request_id INT)
 RETURNS INT
 BEGIN
  DECLARE sf_result INT;
  SET sf_result = 1;
 RETURN sf_result
END

I'm really out of ideas. I'm glad for any help!

Upvotes: 0

Views: 258

Answers (2)

Val Akkapeddi
Val Akkapeddi

Reputation: 1183

You need to change the default delimiter from ';' within the SP body. More info on that here: http://dev.mysql.com/doc/refman/5.1/en/create-procedure.html

Try this:

DELIMITER $$

CREATE FUNCTION aip_sf_choice_valid (request_id INT)
 RETURNS INT
 BEGIN
  DECLARE sf_result INT;
  SET sf_result = 1;
 RETURN sf_result;
END

Upvotes: 2

Grim...
Grim...

Reputation: 16953

Should it have a semicolon after "END"?

Upvotes: 0

Related Questions