CREATE DEFINER=`mazey`@`%` PROCEDURE `sp_find_city_by_ip`(IN `in_visitor_ip` varchar(20),OUT `out_visitor_city` varchar(100)) BEGIN select visitor_city into out_visitor_city from record_visitor where visitor_ip = in_visitor_ip and timestampdiff(hour,visitor_time,now())<72 limit 1; if out_visitor_city is null or out_visitor_city = '' THEN set out_visitor_city=0; end if; END
#测试:
call sp_find_city_by_ip('64.74.215.1',@result); select @result;