Reputation: 31
Here is my code:
create function getten() returns integer
begin
return 10;
end
giving me error message:
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 3
I have no idea what the '' is all about. Any help please?
Upvotes: 2
Views: 959
Reputation: 31
All your answers were great, but only worked after I added 'deterministic' before 'begin'.
Thanks a lot.
Upvotes: 0
Reputation: 24012
When you have only one statement to be executed, you need not use begin
- end
.
create function getten() returns integer return 10;
Otherwise you need default syntax to bind multiple statements within begin
- end
block.
And to restrict the database engine interpret the statements immediately when it finds a default statement close instruction by a semi colon
, we use custom delimiter
.
delimiter //
create function getten() returns integer
begin
return 10;
end;
//
delimiter ;
It would be a good practice to follow using the block type body rather than using an inline single statement.
Upvotes: 0
Reputation: 33945
This works for me...
DELIMITER $$
CREATE FUNCTION getten()
RETURNS INTEGER
BEGIN
RETURN 10;
END;
$$
DELIMITER ;
SELECT getten();
+----------+
| getten() |
+----------+
| 10 |
+----------+
Upvotes: 1
Reputation: 6379
First of all, SQL code is written in big letters. Second, please remember indention.
DELIMITER $$
CREATE FUNCTION getten()
RETURNS INTEGER
LANGUAGE SQL
BEGIN
RETURN 10;
END;
$$
DELIMITER ;
should work like this.
Upvotes: 3
Reputation: 64486
Try this you need to define the type of return in function
DELIMITER $$
CREATE
FUNCTION `getten`()
RETURNS INTEGER
BEGIN
RETURN 10;
END$$
DELIMITER ;
And after creation you can use it like
SELECT `getten`()
Upvotes: 0