0

I have a problema, transofrming a sql server code into mysql. I can't solve the return problem. Error is: [Err] 1415 - Not allowed to return a result set from a function. I tried use select into, but I can't solve it. Any ideas?

 CREATE FUNCTION udf_NORMDIST (v      FLOAT,
                                     mean        FLOAT,
                                     sigma       FLOAT,
                                     cummulative int)
RETURNS NUMERIC(28,8)


BEGIN


 SELECT @x = (v-mean)/sigma;

IF (cummulative = 1) then
   SELECT @z   = abs(@x)/sqrt(2.0);
   SELECT @t   = 1.0/(1.0+0.5*@z);
   SELECT @ans = @t*exp(-@z*@z-1.26551223+@t*(1.00002368+@t*(0.37409196+@t*(0.09678418+@t*(-0.18628806+@t*(0.27886807+@t*(-1.13520398+@t*(1.48851587+@t*(-0.82215223+@t*0.17087277)))))))))/2.0;

   IF @x <= 0 then
    return @ans;
   ELSE
    return  1-@ans;
   END if;
ELSE
   return  exp(-@x*@x/2.0)/sqrt(2.0*3.14159265358979);
END if;

END
  • You appear to have cut the top from your CREATE FUNCTION statement – Job Curtis Mar 17 '20 at 12:49
  • Also, your error probably comes from using SELECT to set variables; correct syntax is `SET @v := (expression);`. – Job Curtis Mar 17 '20 at 12:52
  • You asked this https://stackoverflow.com/questions/60715407/mysql-not-allowed-to-return-a-result-set-from-a-function what didn't apply in the duplicate provided? I don't see a select into in your code. – P.Salmon Mar 17 '20 at 12:52
  • Please review https://dev.mysql.com/doc/refman/8.0/en/select-into.html – P.Salmon Mar 17 '20 at 13:00
  • Does this answer your question? [Mysql : Not allowed to return a result set from a function](https://stackoverflow.com/questions/25305956/mysql-not-allowed-to-return-a-result-set-from-a-function) – P.Salmon Mar 17 '20 at 13:01
  • Problem solved. Just change all variable = something, to :select something into variable – Moises Calderon Arce Mar 17 '20 at 14:21

0 Answers0