使用MySQL函数向表中插入记录

问题描述 投票:0回答:1

我正在尝试使用 MySQL 函数将记录插入到永久表中。我的SQL函数代码与此类似:-

 delimiter //
    create function fn_eval 
    (
    a varchar(36),
    b int,
    c varchar(36)
    ) 
    returns bigint deterministic
begin
      declare retvalue int default 0;
      insert into eval_tbl(a,b,c,d)
      select a,b,c,d
      from
           ((select a,b,c,d from eval_tbl_1
             inner join eval_tbl_2)
             ON eval_tbl_1.c = eval_tbl_2.c)
           )

      SET retvalue=1;   
      return retvalue;
end //
delimiter ;

尝试调用该函数时:

select fn_eval ('1', 2, '3') from dual;

它返回 1。但是,在尝试将其用作查询中的内联函数时,它返回 OK。我无法找出原因。有人可以帮我解决这个问题吗?

mysql function sql-insert
1个回答
0
投票

使用的查询是正确的,但是问题是某个字段返回重复值。这导致查询返回 OK 作为结果。添加了一些条件来选择不同的记录,之后此问题得到解决。

© www.soinside.com 2019 - 2024. All rights reserved.