MySQL Forums
Forum List  »  Newbie

Re: Error: 1305 when I try to call a function in MySQL
Posted by: Barry Galbraith
Date: September 28, 2018 04:07AM

Your syntax for creating the function is not quite correct.

This code works.

DELIMITER $$ 

CREATE FUNCTION triangleType(A INT, B INT, C INT) 
RETURNS VARCHAR(14) 

DETERMINISTIC 

BEGIN 
DECLARE triangle_type VARCHAR(14); 
IF A = B AND B = C AND ((A+B) >C OR (A+C) >B OR (B+C) > A) THEN 
SET triangle_type = "Equilateral"; 

ELSEIF (A=B OR B=C OR A=C) AND ((A+B) >C OR (A+C) >B OR (B+C) > A) THEN 
SET triangle_type = "Isosceles"; 

ELSEIF (A<>B AND B<>C AND A<>C) AND ((A+B) >C OR (A+C) >B OR (B+C) > A)THEN 
SET triangle_type = "Scalene"; 

ELSE 
SET triangle_type = "Not A Triangle"; 
END IF ;

RETURN triangle_type; 

END $$
DELIMITER ;

Then test it

mysql> use practice
Database changed
mysql> select triangleType(3,4,5);
+---------------------+
| triangleType(3,4,5) |
+---------------------+
| Scalene             |
+---------------------+
1 row in set (0.00 sec)

mysql>

Good luck,
Barry.

Options: ReplyQuote


Subject
Written By
Posted
Re: Error: 1305 when I try to call a function in MySQL
September 28, 2018 04:07AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.