嵌套游标在mysql中但显示语法错误

时间:2014-12-28 14:09:36

标签: mysql

DELIMITER $$
USE `g4winners2`$$
DROP PROCEDURE IF EXISTS `wagerMigration`$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wagerMigration`()
BEGIN
DECLARE tbrace_done, tbrunner_done BOOLEAN DEFAULT FALSE;  

 DECLARE race_card_id   INT(10);
 DECLARE race_number   INT(10); 
 DECLARE day_evening VARCHAR(10) ;
 DECLARE locale_type  VARCHAR(50) ;
 DECLARE course_surface  VARCHAR(8) ;
 DECLARE distance_unit VARCHAR(8) ;
 DECLARE race_type  VARCHAR(50)  ;
 DECLARE sex_restriction VARCHAR(8)  ;
 DECLARE age_restriction VARCHAR(8)  ;
 DECLARE purse_usa  DECIMAL(18,2)  ;
 DECLARE maximum_claim_price  DECIMAL(9,2) ;
 DECLARE race_name VARCHAR(120) ;
 DECLARE race_condition  VARCHAR(255) ;
 DECLARE condition_text  TEXT ;
 DECLARE post_time TIME    ;
 DECLARE race_date TIMESTAMP;
 DECLARE is_active  TINYINT(1)  ;
 DECLARE race_status_type INT(11) ;
 DECLARE gait  VARCHAR(50) ;
 DECLARE field_size   SMALLINT(6);
 DECLARE weather  VARCHAR(25);
 DECLARE comments  VARCHAR(128);
 DECLARE odds_updated DATETIME;
 DECLARE pools_updated DATETIME;
 DECLARE win_pool_total  INT(11);
 DECLARE plc_pool_total  INT(11);
 DECLARE shw_pool_total INT(11);


declare horse_name varchar(50);
declare foaling_area char(3);
declare color varchar(255);
declare sex varchar(255);
declare breeder_name varchar(255);
declare sire_name  varchar(255);
declare post_position int(10);
declare program_number  varchar(255);
declare weight_carried int(10);
declare scratch_indicator  varchar(255);
declare trainer_first_name  varchar(255);
declare owner_name varchar(255) ;
declare jockey_first_name varchar(255);
declare odds varchar(255) ;
declare owner_silks  varchar(255);
declare live_odds varchar(255);
declare is_visible tinyint(10);
declare finish_position smallint(6);
declare dead_heat_flag  smallint(6);
declare distance_from_winner  smallint(6);
declare win_pool int(11);
declare plc_pool int(11);
declare shw_pool  int(11);

 DECLARE curRace CURSOR FOR SELECT ee.event_number,"wer",'en_us',ee.surface,ee.distance,ee.race_type_text,ee.sex_restriction ,ee.age_restriction,   
   ee.purse,ee.max_claiming_price,ee.event_name,ee.race_conditions1,ee.track_conditions,ee.post_time,ee.raceday,ee.confirmed_flag,ee.status,ee.gait,
   ee.field_size,ee.weather,ee.comments,ee.odds_updated,ee.pools_updated,ee.win_pool_total,ee.plc_pool_total,ee.shw_pool_total
   FROM ebet.events ee ,ebet.race_meetings trc
   WHERE  trc.meeting_number=ee.meeting_number
   AND trc.raceday=ee.raceday;

 DECLARE CONTINUE HANDLER FOR NOT FOUND SET tbrace_done = TRUE;

OPEN curRace;
cur_race_loop: LOOP
 FETCH FROM curRace INTO race_number ,day_evening ,locale_type,course_surface,distance_unit,race_type,sex_restriction ,age_restriction 
 ,purse_usa ,maximum_claim_price ,race_name ,race_condition ,condition_text 
 ,post_time  ,race_date ,is_active ,race_status_type ,gait 
 ,field_size,weather,comments,odds_updated,pools_updated,win_pool_total,plc_pool_total,shw_pool_total;


    IF tbrace_done THEN
    CLOSE curRace;
    LEAVE cur_race_loop;
    END IF;


SET FOREIGN_KEY_CHECKS=0;
      INSERT INTO g4winners2.tb_races(race_number ,day_evening ,locale_type,course_surface,distance_unit,race_type,sex_restriction ,age_restriction 
 ,purse_usa ,maximum_claim_price ,race_name ,race_condition ,condition_text 
 ,post_time  ,race_date ,is_active ,race_status_type ,gait 
 ,field_size,weather,comments,odds_updated,pools_updated,win_pool_total,plc_pool_total,shw_pool_total)
      VALUES (race_number ,day_evening ,locale_type,course_surface,distance_unit,race_type,sex_restriction ,age_restriction 
 ,purse_usa ,maximum_claim_price ,race_name ,race_condition ,condition_text 
 ,post_time  ,race_date ,is_active ,race_status_type ,gait 
 ,field_size,weather,comments,odds_updated,pools_updated,win_pool_total,plc_pool_total,shw_pool_total);

    SET FOREIGN_KEY_CHECKS=1;
    SET @ID:=(SELECT LAST_INSERT_ID()); 

    SELECT CONCAT ("Result :**", @ID, " ") AS '';
   SET FOREIGN_KEY_CHECKS=0;



    BLOCK2: BEGIN
    DECLARE curRunner CURSOR FOR SELECT er.runner_name,er.area_foaled,er.color,er.sex,er.breeder,er.sire,er.post_position,er.program_number ,er.weight,
er.scratched_flag,er.trainer,er.owner,er.jockey,er.morning_line_odds,er.silks,er.current_odds,'1', er.finish_position,er.dead_heat_flag
  ,er.distance_from_winner,er.win_pool,er.plc_pool,er.shw_pool FROM ebet.runners er ,ebet.events ee 
   WHERE
   ee.meeting_number=er.meeting_number
   AND ee.event_number=er.event_number
   AND  ee.raceday=er.raceday;

    DECLARE CONTINUE HANDLER FOR NOT FOUND SET tbrunner_done = TRUE;
    OPEN curRunner; 
    cur_runner_loop: LOOP
    FETCH curRunner INTO horse_name,foaling_area,color,sex,breeder_name,sire_name,post_position,program_number,weight_carried,scratch_indicator,trainer_first_name,owner_name,jockey_first_name,odds,owner_silks,live_odds,is_visible,finish_position,dead_heat_flag,distance_from_winner,win_pool,plc_pool,shw_pool;

         IF tbrace_done THEN
         set tbrace_done = false;
         CLOSE curRunner;
         LEAVE cur_runner_loop;
        END IF; 

        INSERT INTO g4winners2.tb_race_runners(race_id,horse_name,foaling_area,color,sex,breeder_name,sire_name,post_position,program_number ,
  weight_carried,scratch_indicator ,trainer_first_name ,owner_name ,jockey_first_name,odds ,owner_silks ,live_odds ,is_visible
 ,finish_position,dead_heat_flag,distance_from_winner,win_pool,plc_pool,shw_pool
  ) values(@ID,horse_name,foaling_area,color,sex,breeder_name,sire_name,post_position,program_number ,
  weight_carried,scratch_indicator ,trainer_first_name ,owner_name ,jockey_first_name,odds ,owner_silks ,live_odds ,is_visible
 ,finish_position,dead_heat_flag,distance_from_winner,win_pool,plc_pool,shw_pool);

    END LOOP cur_runner_loop;
    END BLOCK2;
   END LOOP cur_race_loop;

1064您的SQL语法有错误;查看与您的MySQL服务器版本相对应的手册,以获得在''附近使用的正确语法。在第118行(0毫秒)

1 个答案:

答案 0 :(得分:0)

它是否是一个错误的错误,因为它无法编译,因为你没有整个过程的“结束”?你关闭你的循环并阻止,但不是程序。