1
CREATE DEFINER=`root`@`%` FUNCTION  CalSoldeClient (vID_Cli int) RETURNS double
DETERMINISTIC
BEGIN
DECLARE Solde Double;

select sum(Mt_Reg) SumMtReg from t_regcli where id_Cli = vID_Cli;

select sum(Mt_Credit) SumMtCredit from t_credit where id_Cli = vID_Cli;

select SoldeInit from t_clients where id = vID_Cli;

set Solde = SumMtReg - (SumMtCredit +  SoldeInit);


RETURN Solde;
END

ERROR 1415:不允许从函数返回结果集

4

1 回答 1

0

如果您需要在 var 中选择 select 的结果,您应该使用 SELECT INTO 来声明正确的 var

  CREATE DEFINER=`root`@`%` FUNCTION  CalSoldeClient (vID_Cli int) RETURNS double
  DETERMINISTIC
  BEGIN
  DECLARE IntoSoldeInit Double;
  DECLARE SumMtReg Double;
  DECLARE SumMtCredit Double;
  DECLARE Solde Double;

  select sum(Mt_Reg) INTO SumMtReg from t_regcli where id_Cli = vID_Cli;

  select sum(Mt_Credit) INTO SumMtCredit from t_credit where id_Cli = vID_Cli;

  select SoldeInit INTO  IntoSoldeInit from t_clients where id = vID_Cli;

  set Solde = SumMtReg - (SumMtCredit +  IntoSoldeInit);


  RETURN Solde;
  END
于 2019-12-25T10:16:34.263 回答