Query!!1 [message #370475] |
Wed, 01 December 1999 13:41 |
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 |
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 |
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;
|
|
|