Home » RDBMS Server » Server Administration » Query!!1
Query!!1 [message #370475] Wed, 01 December 1999 13:41 Go to next message
Shan
Messages: 14
Registered: December 1999
Junior Member
I have to find cumalutive sum from a table
for example if i have sal column values as
100
300
600
400
My output must be
100
400
1000
1400
Can anyone help me
Re: Query!!1 [message #370476 is a reply to message #370475] Wed, 01 December 1999 14:49 Go to previous messageGo to next message
hmg
Messages: 40
Registered: March 1999
Member
Look at the two answers on the question:

accumulating summarized values from sql
by luis claudio from 7/26/99
Re: Query!!1 [message #370477 is a reply to message #370475] Wed, 01 December 1999 14:53 Go to previous message
Paul
Messages: 164
Registered: April 1999
Senior Member
The PL/SQL below should do the job if you replace the table and colum names with your actual ones. You may want to add some formatting to the output, display additional columns, and add a header.

DECLARE
CURSOR c_sal is
SELECT * FROM salary;
scur c_sal%rowtype;
v_sum NUMBER(10);
BEGIN
OPEN c_sal;
v_sum := 0;
LOOP
FETCH c_sal INTO scur;
EXIT WHEN c_sal%NOTFOUND;
v_sum := v_sum + scur.sal;
DBMS_OUTPUT.PUT_LINE(scur.sal || ' ' || v_sum);
END LOOP;
CLOSE c_sal;
END;
Previous Topic: Testing a stored procedure
Next Topic: Dynamic SQL and Update table question!
Goto Forum:
  


Current Time: Wed Oct 21 11:57:10 CDT 2020