Page 1 of 1

Create function query in MySQL

Posted: Fri 20 Dec 2019 18:51
by AngelusB
I try to execute the query below with DBexpress (TSQLQuery connected to TSQLConnection). The query runs fine in Navicat or other clients, but not in DBExpress (driver DevartMySqlDirect).

DELIMITER $$
CREATE FUNCTION totaalStabu(stabuId int,molenId int,periodeId int) RETURNS float
BEGIN
DECLARE Status FLOAT;
SELECT sum(oh_aantal) INTO Status
FROM sim
WHERE oh_molen= molenId and oh_periode=periodeId and oh_stabu=stabuId
group by oh_stabu;
RETURN Status;
END$$
DELIMITER ;

Error message
#42000You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'DELIMITER $$
CREATE FUNCTION totaalStabu(stabuId int,molenId int,periodeId int)' at line 1

Please help

Re: Create function query in MySQL

Posted: Tue 24 Dec 2019 14:33
by ViktorV
This error is returned by the MySQL server. To solve it, you must correctly modify the request. For example:

Code: Select all

CREATE FUNCTION totaalStabu(stabuId int,molenId int,periodeId int) RETURNS float
BEGIN
DECLARE Status FLOAT;
SELECT sum(oh_aantal) INTO Status
FROM sim
WHERE oh_molen= molenId and oh_periode=periodeId and oh_stabu=stabuId
group by oh_stabu;
RETURN Status;
END