Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I find product of a column

Status
Not open for further replies.

ganeshmb

Programmer
Dec 5, 2001
32
0
0
US
How can I find product of a column in SQL? Is there any aggregate function available for this?
If I want to get the sum of the column salary from table emp, this will do
select sum(salary) from emp
What if I want to get the product of all salaries from emp table?

Any pointer will be greatly appreciated.

 
This is not possible as i know?
but if u want to use sql only then
you can create a function returning a number and u can call this function in ur query.

Eg.
Create or replace function prd_emp return number as
v_prd_sal number := 1;
Cursor c1 is select sal from emp;
begin
for r1 in c1
loop
v_prd_sal := v_prd_sal * nvl(r1.sal,0);
end loop;
return v_prd_sal;
end;

create this stored function and use in sql query.

select prd_emp from dual;

best luck
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top