MySQL Forums
Forum List  »  Triggers

Re: Need help creating mysql trigger
Posted by: Peter Brawley
Date: May 07, 2020 09:41AM

Sorry, I reversed new and ip_lookup ...

drop trigger if exists access_ins;
delimiter go
create trigger access_ins before insert on access for each row
begin
  declare vcountry, varea, vcity varchar(64);
  select country,area,city into vcountry,varea,vcity
  from ip_lookup
  where NEW.ip_address between ip_lookup.start_ip and ip_lookup.end_ip
  limit 1; /* iplookup table might have multiple rows matching given range */
  if vcountry is not null then
    set NEW.country=vcountry, NEW.area=varea, NEW.city=vcity;
  /* else ... code to handle error */
  end if;
end;
go
delimiter ;

Options: ReplyQuote


Subject
Views
Written By
Posted
220
May 03, 2020 07:42AM
Re: Need help creating mysql trigger
71
May 07, 2020 09:41AM


Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.