By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
create table table_ent (cod_prod, date_ent, vl_prod) as
select 362, to_date('14/09/2015', 'DD/MM/YYYY'), 100 from dual
union all select 362, to_date('15/09/2015', 'DD/MM/YYYY'), 150 from dual
union all select 362, to_date('16/09/2015', 'DD/MM/YYYY'), 10 from dual
union all select 362, to_date('05/10/2016', 'DD/MM/YYYY'), 20 from dual
union all select 362, to_date('06/10/2016', 'DD/MM/YYYY'), 300 from dual
union all select 362, to_date('07/10/2016', 'DD/MM/YYYY'), 460 from dual
union all select 362, to_date('08/10/2016', 'DD/MM/YYYY'), 510 from dual
union all select 362, to_date('23/10/2016', 'DD/MM/YYYY'), 620 from dual
union all select 362, to_date('24/10/2016', 'DD/MM/YYYY'), 750 from dual
union all select 362, to_date('25/10/2016', 'DD/MM/YYYY'), 810 from dual
union all select 362, to_date('30/10/2019', 'DD/MM/YYYY'), 920 from dual;
11 rows affected
create table table_out (cod_prod, date_out, vl_prod) as
select 362, to_date('01/10/2016', 'DD/MM/YYYY'), 700 from dual
union all select 362, to_date('07/10/2016', 'DD/MM/YYYY'), 800 from dual
union all select 362, to_date('29/10/2016', 'DD/MM/YYYY'), 100 from dual
union all select 362, to_date('01/10/2016', 'DD/MM/YYYY'), 800 from dual;
4 rows affected
select a.cod_prod, a.date_out, a.vl_prod, b.cod_prod as cod_prod,
max(b.vl_prod) keep (dense_rank last order by b.date_ent) as vl_prod, max(b.date_ent) as date_ent
from table_out a
join table_ent b on b.cod_prod = a.cod_prod and b.date_ent < a.date_out
group by a.cod_prod, a.date_out, b.cod_prod, a.vl_prod --, b.vl_prod
order by a.cod_prod;
COD_PROD | DATE_OUT | VL_PROD | COD_PROD | VL_PROD | DATE_ENT |
---|---|---|---|---|---|
362 | 01-OCT-16 | 700 | 362 | 10 | 16-SEP-15 |
362 | 01-OCT-16 | 800 | 362 | 10 | 16-SEP-15 |
362 | 07-OCT-16 | 800 | 362 | 300 | 06-OCT-16 |
362 | 29-OCT-16 | 100 | 362 | 810 | 25-OCT-16 |