mysql存储过程
drop procedure count_points; create procedure count_points() begin declare n_Latitude double; declare n_Longitude double; declare isExist int; declare countExist int default 0; declare n_cellname varchar(255); -- 定义游标遍历时,作为判读是否遍历完全被记录的标记 declare num int default 0; declare lat_long_list CURSOR FOR select Longitude,Latitude,cellname from table_name; -- 声明当游标遍历完全被记录后将标志变量置成某个值 declare continue handler for sqlstate '02000' set num=1; truncate table t_cell_name; -- 打开游标 open lat_long_list; -- 将游标中的值赋值给变量,要注意sql结果列的顺序 fetch lat_long_list into n_Longitude,n_Latidute,n_cellname; -- 打印值 -- select n_Longitude,n_Latitude; -- while循环 while num<>1 do select count(*) into isExist from tableb; if isExist = 1 then set countExist = countExist +1; insert into t_cell_name(cellname) values(n_cellname); end if; -- 循环变量下一条数据,将游标中的值赋值给变量,要注意sql结果列的顺序 fetch lat_long_list into n_Longitude,n_Latitude,n_cellname; end while; -- 关闭游标 close lat_long_list; -- 打印值 select countExist; end