· 7 years ago · Jan 21, 2019, 04:26 AM
1#CREATE TABLE geom (n varchar(100), g POINT NOT NULL SRID 0, SPATIAL INDEX(g));
2#delete from geom;
3insert into geom values ('1', st_pointfromtext('POINT(-80.2329529 26.2207623)'));
4insert into geom values ('2', st_pointfromtext('POINT(-80.178399 26.247929)'));
5insert into geom values ('3', st_pointfromtext('POINT(-80.175934 26.236896)'));
6insert into geom values ('4', st_pointfromtext('POINT(-80.196904 26.187626)'));
7insert into geom values ('5', st_pointfromtext('POINT(-80.182951 26.188153)'));
8insert into geom values ('6', st_pointfromtext('POINT(-80.323396 26.831648)'));
9
10
11
12# 26.247929 -80.178399
13# 26.236896 -80.175934
14# 26.187626 -80.196904
15# 26.188153 -80.182951
16#
17# 26.571267 -80.165731
18
19DROP PROCEDURE IF EXISTS proc_loop_test;
20CREATE PROCEDURE proc_loop_test()
21BEGIN
22 DECLARE int_val INT DEFAULT 0;
23 test_loop : LOOP
24 IF (int_val = 10000) THEN
25 LEAVE test_loop;
26 END IF;
27
28 SET int_val = int_val +1;
29 insert into geom values ('6', st_pointfromtext('POINT(-80.323396 26.831648)'));
30 END LOOP;
31END;
32
33call proc_loop_test;
34
35SET @g1 = st_pointfromtext('POINT(-80.178399 26.247929)');
36select *
37from geom
38where st_distance_sphere(@g1, g) < 50000