declare 
  cursor c_det is
  select * from movimientocajadetres;
  ref  movimientocaja.referencia%type;
begin
  for a in c_det
  loop
    if a.documento is null then
       ref := '0';
     else
       ref := a.documento;
    end if;
    update movimientocaja
    set tipocambio=a.tipocambio,
        referencia=ref
    where cia    = a.cia
    and   caja   = a.caja
    and   cajero = a.cajero
    and   dia    = a.dia
    and  concepto = a.concepto;
  end loop;
end;