sum of squares of 1st n natural numbers using PL/SQL
kr61665May 3 2011 — edited May 3 2011Hi,
I have tried the below procedure but getting individual results only.I want to add all the results i.e (1+4+9).Can anyone please tell me how to query it.
create or replace procedure test_sum_sqrs
as
begin
declare
n number;
s number :=1;
begin
n :=&n;
for i in 1..n
loop
s :=(i*1)*(i*1);
DBMS_OUTPUT.PUT_LINE('Individual values'||' '||s);
end loop;
DBMS_OUTPUT.PUT_LINE('Output is'||' '||s);
end;
end test_sum_sqrs;
Procedure created.
SQL> exec test_sum_sqrs;
Individual values 1
Individual values 4
Individual values 9
Output is 9