Home » SQL & PL/SQL » SQL & PL/SQL » Re: Cummulative SUM
Re: Cummulative SUM [message #19044] Tue, 26 February 2002 22:53 Go to next message
ajay
Messages: 45
Registered: December 2000
Member
This is fine....
i tried running the select u have given..
and every time it is run it starts adding from the last run's max total
e.g suppose the query resulted in records with running total sal as 1005 , and the next run of same query will start totaling from 1005
Re: Cummulative SUM [message #19047 is a reply to message #19044] Wed, 27 February 2002 01:03 Go to previous message
pratap kumar tripathy
Messages: 660
Registered: January 2002
Senior Member
this time i have changed a code a little bit, to avoid any ambiguity

***always use this command "exec running_total.init;"
before running the sql statement, which initlalize the total.

have a look at the code , i think it is quite straight forward

hope it helps!!!

---------------------------
CREATE OR REPLACE package running_total as
total number:=0;
function addme(n number) return number;
pragma restrict_references(addme,wnds);
procedure init;
end;
/

CREATE OR REPLACE package body running_total as
-----
function addme(n number) return number as
begin
total:=total+n;
return total;
end;
-----
procedure init as
begin
total:=0;
end;
-----
end;
/

exec running_total.init;
select sal,running_total.addme(sal) from emp
Previous Topic: How to find n max rows from a table without using "order by" or "group by"
Next Topic: Create Procedure that returns recordset
Goto Forum:
  


Current Time: Thu Mar 28 19:09:17 CDT 2024