vjohnny8
July 19th, 2011, 12:38 PM
Hi everyone,
There will be no gap concept in the dates as given below. it will take the current rate of the max date that is currently present in the database i.e
14-jul-11 2.5
13-jul-11 3.5 5.6
the 2 above rows are currently present in the database, now if a new row is inserted as below,
date curr_rate prev_rate
17-jul-11 1.5 2.5
then the previous rate that is shown for 17th jul, is the current rate of 14th jul ( which is already present in the database)
so in simple terms, the previous rate of 17 jul should display the value of the current rate of the max date already present in the database.
how can i modify the below trigger to achieve this ?
create table t1
( index_id number,
time_vertex number,
date1 date,
date_rate number(10,2),
prev_rate number(10,2) )
create or replace trigger t1_ai before insert on t1 for each row
begin
begin
Select date_rate
into :new.prev_rate
from t1
where rowid in
(select rn from
(select rowid rn, dense_rank() over (partition by index_id,time_vertex order by date1 desc) rnk from t1
where index_id = :new.index_id and
time_vertex = :new.time_vertex and
date1 < :new.date1
) where rnk =1 );
exception when no_data_found then
:new.prev_rate := -1;
end;
end;
There will be no gap concept in the dates as given below. it will take the current rate of the max date that is currently present in the database i.e
14-jul-11 2.5
13-jul-11 3.5 5.6
the 2 above rows are currently present in the database, now if a new row is inserted as below,
date curr_rate prev_rate
17-jul-11 1.5 2.5
then the previous rate that is shown for 17th jul, is the current rate of 14th jul ( which is already present in the database)
so in simple terms, the previous rate of 17 jul should display the value of the current rate of the max date already present in the database.
how can i modify the below trigger to achieve this ?
create table t1
( index_id number,
time_vertex number,
date1 date,
date_rate number(10,2),
prev_rate number(10,2) )
create or replace trigger t1_ai before insert on t1 for each row
begin
begin
Select date_rate
into :new.prev_rate
from t1
where rowid in
(select rn from
(select rowid rn, dense_rank() over (partition by index_id,time_vertex order by date1 desc) rnk from t1
where index_id = :new.index_id and
time_vertex = :new.time_vertex and
date1 < :new.date1
) where rnk =1 );
exception when no_data_found then
:new.prev_rate := -1;
end;
end;