drop table partner;
create table partner (
  nev varchar(100),
  nem char(1),
  eletkor int,
  varos varchar(100),
  partner_neve varchar(100)
);

create or replace trigger tarskereso
before insert on partner
for each row
declare
  pnev varchar(100);
  cursor tobbiek is select nev from partner where partner_neve = '---'
  and nem != :new.nem
  and varos = :new.varos
  and abs(:new.eletkor - eletkor) <= 10
  order by (abs(:new.eletkor - eletkor)) asc;
begin
  open tobbiek;
  fetch tobbiek into pnev;
  if tobbiek%found then
    :new.partner_neve := pnev;
    update partner set partner_neve = :new.nev where nev = pnev;
  end if;
  close tobbiek;
end;