Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: row multilication
In article <9ehvt4$o84$1_at_tilde.csc.ti.com>, Norazman <norazman_at_ti.com>
writes:
>Hi,
>
>Anybody know how to get a multiply of return row from a query.
>
>Example:
>
>Select Age from User
>Age:
>.......
>1
>2
>3
>4
>
>I want to have something like this:
>
>Age:
>----
>1
>2
>3
>4
>----
>24 - result of multilying 1x2x3x4
>
>Thanks
>
Hey, this is Oracle, not matlab! :)
I'm pretty sure there's no really quick way. You'll probably have to use a little PL/SQL... write a function with a cursor, something like
declare
cursor mult_cursor is
select age from user;
result NUMBER;
age_val mult_cursor%ROWTYPE;
begin
result := 1;
for age_val in mult_cursor
loop
result := result * age_val.age;
end loop;
return result;
end;
end;
(I haven't tested this, it may take debugging)
Good luck!