我的数据库名称是dfeb
,我有一个名为invdt
的表和名为batch_number
,id
的列。我想得到batch_number
所在的id = 59,使用函数。但错误显示为function does not exist
。
DELIMITER $$
CREATE
FUNCTION `dfeb`.`get_quantity`(PID)
RETURNS VARCHAR
BEGIN
DECLARE NAME_FOUND VARCHAR DEFAULT "";
SELECT `batch_number` INTO NAME_FOUND FROM `invdt` WHERE ID = PID;
RETURN NAME_FOUND
END$$
DELIMITER ;
SELECT `get_quantity`(59) FROM `invdt`
答案 0 :(得分:0)
尝试:
DELIMITER $$
-- CREATE FUNCTION `dfeb`.`get_quantity`(PID)
CREATE FUNCTION `dfeb`.`get_quantity`(PID INT)
-- RETURNS VARCHAR
RETURNS VARCHAR(200)
BEGIN
-- DECLARE NAME_FOUND VARCHAR DEFAULT "";
DECLARE NAME_FOUND VARCHAR(200) DEFAULT "";
SELECT `batch_number` INTO NAME_FOUND FROM `invdt` WHERE ID = PID;
-- RETURN NAME_FOUND
RETURN NAME_FOUND;
END$$
DELIMITER ;
-- SELECT `get_quantity`(59) FROM `invdt`
SELECT `dfeb`.`get_quantity`(59) FROM `invdt`;
<强>更新强>
CREATE FUNCTION `dfeb`.`get_quantity`(PID INT)
.
.
.
-- SELECT `get_quantity`(59) FROM `invdt`
SELECT `dfeb`.`get_quantity`(59) FROM `invdt`;
或者
USE `dfeb`;
CREATE FUNCTION `get_quantity`(PID INT)
.
.
.
SELECT `get_quantity`(59) FROM `invdt`;