MySQL procedure 질문입니다~ 0 2 1,705

by 릿죠로 [MySQL] [2016.08.03 18:09:40]


DROP PROCEDURE IF EXISTS procedure_one;
CREATE PROCEDURE procedure_one ()

BEGIN
  DECLARE idx varchar(255);
  DECLARE lat double;
  DECLARE lng double;
  DECLARE zoom int;
 
 
 
  DECLARE exit_loop BOOLEAN;
  DECLARE cur1 CURSOR FOR select pokestop_id, latitude, longitude, 4 from pokestop;
  DECLARE CONTINUE HANDLER FOR NOT FOUND SET exit_loop = TRUE;
 
  OPEN cur1;
 
   read_loop: LOOP
  
   FETCH cur1 INTO idx, lat, lng, zoom;
   IF exit_loop THEN
      LEAVE read_loop;     
   END IF;
  
   CALL pokemonmap.location_definer_2(idx, lat, lng, zoom);
  
   END LOOP;
 
  CLOSE cur1;

END;

-----------------------------------------------------------------------------------------------------------------------------------

DROP PROCEDURE IF EXISTS procedure_two;
CREATE PROCEDURE procedure_two(
                                              IN idx varchar(255),
                                              IN lat double,
                                              IN lng double,
                                              IN zoom int
                                              )
  
                                             
                                             
                                             
BEGIN

  DECLARE scale int(3);
  DECLARE worldx float;
  DECLARE worldy float;
  DECLARE siny float;
  DECLARE tilex int;
  DECLARE tiley int;
  DECLARE tileindex int;
 
 
  SET scale =  zoom;
  
  SET siny = sin(lat * 3.1415926 / 180);
  SET siny = min( max(siny, -0.9999), 0.9999);
 
  SET worldx = 256 * (0.5 + lng / 360);
  SET worldy = 256 * (0.5 - log((1 + siny) / (1 - siny)) / (4 * 3.1415926));
 
  SET tilex = floor(worldx * scale / 256);
  SET tiley = floor(worldy * scale / 256);
 
  SET tileindex = tilex * tiley;
 
 
  update pokestop_test set zoom4 = tileindex where pokestop_id = idx;
 
END;
 

--------------------------------------------------------------------------------------------------------------------------------

 

위의 procedure_one 에서 procedure_two 를 불러오는 구조로 만들고 있는데 procedure_one 은 compile 잘 되었는데

procedure_two는 컴파일에서 오류가 나네요

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ' -0.9999), 0.9999);
 
  SET worldx = 256 * (0.5 + lng / 360);
  SET worldy =' at line 25

고수님들 도와주세요 ㅠㅠ

 

by 마농 [2016.08.03 18:21:50]

그룹함수(Min/Max) 사용이 의심됩니다.
  - 변경전 : SET siny = MIN(MAX(siny, -0.9999), 0.9999);
  - 변경후 : SET siny = LEAST(GREATEST(siny, -0.9999), 0.9999);


by 릿죠로 [2016.08.04 14:33:57]

마농님 정말정말 감사합니다!

댓글등록
SQL문을 포맷에 맞게(깔끔하게) 등록하려면 code() 버튼을 클릭하여 작성 하시면 됩니다.
로그인 사용자만 댓글을 작성 할 수 있습니다. 로그인, 회원가입