------解决方案--------------------
Create Or Replace Function Number_Sum(Num Number) Return Number As c_Return Number; c_Tmp Number; Begin c_Return := 0; c_Tmp := 0; While c_Tmp <= Num Loop c_Return := c_Return + c_Tmp; c_Tmp := c_Tmp + 1; End Loop; Return c_Return; End Number_Sum;
------解决方案--------------------
SQL code
create or replace procedure p_sum(ma in number) is
vi_sum number(6) := 0;
vi_n number(4) := 1;
begin
while vi_n <= ma
loop
vi_n := vi_n + 1;
vi_sum := vi_sum + vi_n;
end loop;
dbms_output.put_line(vi_sum);
exception
when others then
dbms_output.put_line('error');
end;
------解决方案--------------------