I have a problem. I created a function in MySQL which returns a String (varchar data type).
我有个问题。我在MySQL中创建了一个函数,它返回一个String(varchar数据类型)。
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:
当我调用函数如调用SafetyStockChecker(16,16)时,我收到此错误:
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查询:致电SafetyStockChecker(16,16)错误代码:1305程序inv_sbmanis.SafetyStockChecker不存在执行时间:00:00:00:000转移时间:00:00:00:000总时间:00:00:00:000
What's wrong with the function?
这个功能有什么问题?
2 个解决方案
#1
10
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:
你现在的做法是打电话给STORED PROCEDURE。这就是为什么错误说:
PROCEDURE inv_sbmanis.SafetyStockChecker does not exist
程序inv_sbmanis.SafetyStockChecker不存在
because it is searching for a Stored procedure and not a function.
因为它正在搜索存储过程而不是函数。
#2
2
You should use
你应该用
SELECT SafetyStockChecker(16,16)
#1
10
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:
你现在的做法是打电话给STORED PROCEDURE。这就是为什么错误说:
PROCEDURE inv_sbmanis.SafetyStockChecker does not exist
程序inv_sbmanis.SafetyStockChecker不存在
because it is searching for a Stored procedure and not a function.
因为它正在搜索存储过程而不是函数。
#2
2
You should use
你应该用
SELECT SafetyStockChecker(16,16)