Reputation: 688
I have this piece of code PL/SQL code in a procedure
for rec in(select t.val, t.cat from table t where a=1)
Loop
v:=(rec.val*rec.cat)/2;
end Loop;
How I can get the sum of all 'v' values?
Upvotes: 0
Views: 79
Reputation: 1095
This will create the sum in another variable, named tempSum
DECLARE
tempSum number (6);
tempSum := 0;
for rec in(select t.val, t.cat from table t where a=1)
Loop
v:=(rec.val*rec.cat)/2;
tempSum := tempSum + V;
end Loop;
Upvotes: 1
Reputation: 2496
Best way:
select sum(t.val * t.cat / 2) into l_val_cat_sum from table t where a = 1;
Upvotes: 0