Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error Code: 1305 MySQL, Function does not Exist

Tags:

function

mysql

I have a problem. I created a function in MySQL which returns a String (varchar data type).

Here's the syntax:

DELIMITER $$
USE `inv_sbmanis`$$
DROP FUNCTION IF EXISTS `SafetyStockChecker`$$

CREATE DEFINER=`root`@`localhost` FUNCTION `SafetyStockChecker`
(jumlah INT, safetystock INT)   
RETURNS VARCHAR(10) CHARSET latin1
BEGIN
DECLARE statbarang VARCHAR(10);
IF jumlah > safetystock THEN SET statbarang = "Stabil";
ELSEIF jumlah = safetystock THEN SET statbarang = "Perhatian";
ELSE SET statbarang = "Kritis";
END IF;
RETURN (statbarang);
END$$
DELIMITER ;

When I call the function like call SafetyStockChecker(16,16), I get this error:

Query : call SafetyStockChecker(16,16)
Error Code : 1305
PROCEDURE inv_sbmanis.SafetyStockChecker does not exist
Execution Time : 00:00:00:000
Transfer Time : 00:00:00:000
Total Time : 00:00:00:000

What's wrong with the function?

like image 966
randytan Avatar asked Apr 18 '13 08:04

randytan


2 Answers

That is not the correct way to call a function. Here's an example to call a function:

SELECT SafetyStockChecker(16,16) FROM TableName

The way you are doing now is for calling a STORED PROCEDURE. That is why the error says:

PROCEDURE inv_sbmanis.SafetyStockChecker does not exist

because it is searching for a Stored procedure and not a function.

like image 168
John Woo Avatar answered Nov 09 '22 05:11

John Woo


You should use

SELECT SafetyStockChecker(16,16)
like image 4
Amit Garg Avatar answered Nov 09 '22 06:11

Amit Garg