ichinisanshi
ichinisanshi

Reputation: 53

MySql mariaDB CREATE FUNCTION DELIMITER doesnt work. has error near ''

im going insane. i dont know whats wrong with this code i see nothing wrong in it. but it kept reading thee same error each time i put the $$ after the "END". please help guys... here is my code

DELIMITER $$
CREATE FUNCTION fungsi1 (a int)
RETURNS INT
DETERMINISTIC
BEGIN
DECLARE nilaiasal INT;
DECLARE teks VARCHAR(50);
SET nilaiasal = a * a;
IF nilaiasal > 100 THEN
SET teks  = 'LEBIH DARI SERATUS';
ELSEIF nilaiasal < 100 THEN
SET teks  = 'KURANG DARI  SERATUS';
INSERT INTO table1 (dataone,datatwo) VALUES(a,teks);
SELECT * FROM table1;
RETURN (nilaiasal);
END $$
DELIMITER ;

And the error is this

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 15

Please help me. I've looked up create functions error and there hasnt been anyone that has a problem near ''.

Upvotes: 1

Views: 593

Answers (1)

slaakso
slaakso

Reputation: 9080

You might want to consider using a stored procedue instead of a function if you want to return a result set.

You are missing END IF; as Ergest Basha suggested and you are trying to return a result set from a function which is not allowed.

Upvotes: 1

Related Questions