Re: Cummulative SUM [message #19044] |
Tue, 26 February 2002 22:53 |
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 |
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
|
|
|