Coast Line
asked on
Calculating the Data in Oracle
I had to calculate varience in oracle. I know there is a function in oracle named varience
I am doing VARIENCE as (MyExpectedData - MyActualReturns)
1. How Does Varience Work...
2. Alo I want to Return data as Percentage for one of the column which is a combination of two columns as:
(Column1/Column2)*100 as myNewData
But this does has errors, if there is a division by zero. It throws an error and second how do i bring its result in percentage sign with it
Please Guide
Thanks
I am doing VARIENCE as (MyExpectedData - MyActualReturns)
1. How Does Varience Work...
2. Alo I want to Return data as Percentage for one of the column which is a combination of two columns as:
(Column1/Column2)*100 as myNewData
But this does has errors, if there is a division by zero. It throws an error and second how do i bring its result in percentage sign with it
Please Guide
Thanks
For how variance work ... please find the link below :
http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions212.htm
http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions212.htm
ASKER
yes!
sample data like this
select
column1, column2,
(column1/column2 * 100) as column3
from my table
So this is how i am getting the data, But please also tell if there is a divison by zero then how we do handle it
sample data like this
select
column1, column2,
(column1/column2 * 100) as column3
from my table
So this is how i am getting the data, But please also tell if there is a divison by zero then how we do handle it
Please find the example as :
create temp_t (col1 number , col2 number);
begin
insert into temp_t values (1,1);
insert into temp_t values (1,0);
end;
commit;
Error Query:
SQL> select (((col1/col2)* 100 )||'%') data_percent from temp_t ;
Valid Query:
SQL> select ((CASE WHEN (NVL(max(col2),0) = 0) THEN 0 ELSE ( col1/col2)* 100 END)||'%') percent
from temp_t
group by col1,col2;
create temp_t (col1 number , col2 number);
begin
insert into temp_t values (1,1);
insert into temp_t values (1,0);
end;
commit;
Error Query:
SQL> select (((col1/col2)* 100 )||'%') data_percent from temp_t ;
Valid Query:
SQL> select ((CASE WHEN (NVL(max(col2),0) = 0) THEN 0 ELSE ( col1/col2)* 100 END)||'%') percent
from temp_t
group by col1,col2;
you can remove the max from the valid query ......
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
why using groupby
ASKER
also if omit group it will display correct data rt, also does it handles the decimal places also
...you can remove group by condition...
ASKER
also will decilams play good
just try it and let us know if you get any issues
select (((1/1)*100)||'%') percent_data from dual ;
>>> this does has errors, if there is a division by zero.
Can you provide some sample data so that we can check ?