Select clausule inside pl/sql function return wrong value

試著忘記壹切 提交于 2020-05-09 17:15:14

问题


When I do this:

select sum(m.mot)
from rmtq mq
join rmo m on mq.id = m.id
where mq.another = 138;

return value = 2, which is correct. But when I put this code inside a function:

create or replace function get(another in number) return number
   is ret number := 0;
   begin
      select sum(m.mot)
              into ret
              from rmtq mq
              join rmo m on mq.id = m.id
              where mq.another = another
       return(ret);
    end;

and I call:

exec dbms_output.put_line(get(138));

return value = 39, which is incorrect. What is that 39?


回答1:


The comments were right to question; lest anyone waste time on this you have to write the names of the parameters correctly, for example:

create or replace function get(p_another in number) return number
   is ret number := 0;
   begin
      select sum(m.mot)
              into ret
              from rmtq mq
              join rmo m on mq.id = m.id
              where mq.another = p_another
       return(ret);
    end;


来源:https://stackoverflow.com/questions/38981825/select-clausule-inside-pl-sql-function-return-wrong-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!