4

我四处浏览,其他解决方案似乎对我不起作用。尝试在 MySQL 中创建此函数时,我不断收到“未找到函数返回”错误。知道为什么吗?

CREATE FUNCTION `mydb`.`myfunction`(Name varchar(20))
RETURNS int
LANGUAGE SQL
NOT DETERMINISTIC
SELECT SUM(Transaction.Bought) INTO @Qty FROM Transaction WHERE Transaction.Name = Name;
RETURN @Qty
4

3 回答 3

1

或者,试试这个,

DELIMITER $$
CREATE FUNCTION `myfunction`(Name varchar(20))
RETURNS int
LANGUAGE SQL
NOT DETERMINISTIC
BEGIN

  DECLARE returnVal int;

  SELECT SUM(`Transaction`.Bought) INTO returnVal 
  FROM `Transaction` 
  WHERE `Transaction`.Name = Name;

  RETURN returnVal;

END$$
DELIMITER ;
于 2012-09-17T01:15:52.047 回答
1

尝试这个

DELIMITER $$
CREATE FUNCTION `myfunction`(`Name` VARCHAR(20) CHARSET utf8) RETURNS INT NOT DETERMINISTIC
READS SQL DATA
MAIN: BEGIN
DECLARE returnVal int;
SELECT SUM(`Transaction`.Bought) INTO returnVal FROM `Transaction` WHERE `Transaction`.Name = Name;
RETURN returnVal;
END MAIN;$$
DELIMITER ;
于 2012-09-17T01:41:34.680 回答
0
delimiter //
create function myfun1234 (i int,j int)
returns int 
begin 
      declare x int ;
       declare    y int ;
        declare  z int ;
      set x=10;
      set y=20;
      if (1<=x && j>=y )then 
      set z=i+j;
      end if;
    return z;
      end; //


-- error1   FUNCTION myfun12 ended without RETURN 
于 2015-05-19T01:20:19.537 回答