De standaard RANGE / ROWS voor FIRST_VALUE (zoals bij elke andere analytic functie) is BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW.
Als je IGNORE NULLS toevoegt, worden NULL-waarden uitgesloten bij het opbouwen van het bereik.
De RANGE wordt dan effectief BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW EXCEPT FOR THE NULL ROWS (wat geen geldige OVER-clausule is).
Omdat je txt-waarden die NULL zijn hoge id's hebben, worden ze eerst geselecteerd, en hun bereiken komen leeg uit, omdat er geen niet-NULL-rijen tussen hen en UNBOUNDED PRECEDING liggen.
Je moet ofwel de ORDER BY ofwel de RANGE-clausule van je query wijzigen.
De ORDER BY wijzigen duwt de rijen met NULL-id's naar het einde van het venster, zodat een niet-NULL-waarde (als die bestaat) altijd als eerste wordt geselecteerd en het RANGE-bereik gegarandeerd daar begint:
with t as (
select 450 id, null txt, 3488 id_usr from dual union all
select 449, null, 3488 from dual union all
select 79, 'A', 3488 from dual union all
select 78, 'X', 3488 from dual
)
select id, txt, id_usr,
first_value(txt) over (partition by id_usr order by NVL2(TXT, NULL, id) DESC) first_one
from tDe RANGE wijzigen herdefinieert het venster zodat het alle niet-NULL-rijen in de partitie bevat:
with t as (
select 450 id, null txt, 3488 id_usr from dual union all
select 449, null, 3488 from dual union all
select 79, 'A', 3488 from dual union all
select 78, 'X', 3488 from dual
)
select id, txt, id_usr,
first_value(txt IGNORE NULLS) over (
partition by id_usr
order by id DESC
RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) first_one
from t