Reputation: 27554
mysqlfile.sql:
DROP FUNCTION IF EXISTS func1;
DELIMITER //
CREATE FUNCTION func1(N INT) RETURNS INT
BEGIN
RETURN (
select * from Employee;
);
END//
DELIMITER ;
executed source mysqlfile.sql
, got an error:
ERROR 1064 (42000): 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 ';
);
END' at line 4
How should I modify the code?
Upvotes: 0
Views: 43
Reputation: 12391
A function returns 1 value, as far I can see you want to return a dataset. You must create procedure in order to get what you need.
DELIMITER //
CREATE PROCEDURE getEmployees()
BEGIN
SELECT * FROM employee;
END //
DELIMITER ;
You can call it by call getEmployees();
Upvotes: 1
Reputation: 111
TRY:
DROP FUNCTION IF EXISTS func1;
CREATE FUNCTION func1(N INT) RETURNS INT
BEGIN
DECLARE select_var VARCHAR;
SET select_var = (SELECT * FROM Employee);
RETURN VARCHAR(255);
END$$
Hope it'll solve your issue
Upvotes: 0
Reputation: 2588
you missed a semicolon after END and have an extra after the select
DROP FUNCTION IF EXISTS func1;
DELIMITER //
CREATE FUNCTION func1(N INT) RETURNS INT
BEGIN
RETURN (
select * from Employee
);
END;//
DELIMITER ;
Upvotes: 1