Re: Error: 1305 when I try to call a function in MySQL
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.
Subject
Written By
Posted
September 27, 2018 04:16PM
September 27, 2018 06:57PM
September 27, 2018 08:12PM
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.