create or replace FUNCTION ULTIMO_VORMONAT (datum IN date) RETURN DATE is v_ultimo date; BEGIN select ultimo into v_ultimo from ultimo_as where jahr = extract(year from datum - to_yminterval('0-1')) and monat = extract(month from datum -to_yminterval('0-1')); RETURN v_ultimo; END;