1

このトリガーを実行すると、次のようなエラーがスローされます。

#1064-SQL構文にエラーがあります。27行目の「END」の近くで使用する正しい構文については、MySQLサーバーのバージョンに対応するマニュアルを確認してください。

delimiter //

CREATE TRIGGER `after_tblgps_insert` AFTER INSERT ON `tbl_gps`
FOR EACH ROW BEGIN
DECLARE cab_meter_new VARCHAR(10);
DECLARE cab_cost_new VARCHAR(10);
DECLARE cab_meter_old VARCHAR(10);
DECLARE cab_cost_old VARCHAR(10);
DECLARE pr_pnr_no  VARCHAR(15);
DECLARE pr_dest_id  VARCHAR(15);

select NEW.gps_rs232,NEW.gps_cab_bus,gps_rs232,gps_cab_bus into @cab_meter_new,@cab_cost_new,@cab_meter_old,@cab_cost_old from tbl_gps where gps_imei = NEW.gps_imei order by gps_id asc limit 0,1;

IF @cab_meter_new = 1 and @cab_meter_old = 0 THEN
BEGIN
select `booking_pnr_no` into @pr_pnr_no from tbl_booking where booking_alloted_vehicle = (select taxi_id from tbl_taxi where taxi_imei = NEW.gps_imei ) AND booking_status = 13;
select trip_dst_area_id into @pr_dest_no from tbl_trip where pnr_id = @pr_pnr_no order by trip_id desc limit 0,1;
update tbl_taxi set taxi_cur_status = 12,taxi_cur_area = @pr_dest_no where taxi_id = NEW.gps_cab_bus;
update tbl_booking set booking_status = 9 where booking_pnr_no = @pr_pnr_no;
END;
ELSE IF @cab_meter_new = 0 and @cab_meter_old = 1 THEN
BEGIN
select `booking_pnr_no` into @pr_pnr_no from tbl_booking where booking_alloted_vehicle = (select taxi_id from tbl_taxi where taxi_imei = NEW.gps_imei ) AND booking_status = 9;
select trip_dst_area_id into @pr_dest_no from tbl_trip where pnr_id = @pr_pnr_no order by trip_id desc limit 0,1;
update tbl_taxi set taxi_cur_status = 10,taxi_cur_area = @pr_dest_no where taxi_id = NEW.gps_cab_bus;
update tbl_booking set booking_status = 8 where booking_pnr_no = @pr_pnr_no;
END;
END IF
END //
delimiter ;
4

2 に答える 2

1

このコードを試してください

delimiter //

CREATE TRIGGER `after_tblgps_insert` AFTER INSERT ON `tbl_gps`
FOR EACH ROW BEGIN
DECLARE cab_meter_new VARCHAR(10);
DECLARE cab_cost_new VARCHAR(10);

    DECLARE cab_meter_old VARCHAR(10);
    DECLARE cab_cost_old VARCHAR(10);
    DECLARE pr_pnr_no  VARCHAR(15);
    DECLARE pr_dest_id  VARCHAR(15);

    select NEW.gps_rs232,NEW.gps_cab_bus,gps_rs232,gps_cab_bus into @cab_meter_new,@cab_cost_new,@cab_meter_old,@cab_cost_old from tbl_gps where gps_imei = NEW.gps_imei order by gps_id asc limit 0,1;

    IF @cab_meter_new = 1 and @cab_meter_old = 0 THEN
    BEGIN
    select `booking_pnr_no` into @pr_pnr_no from tbl_booking where booking_alloted_vehicle = (select taxi_id from tbl_taxi where taxi_imei = NEW.gps_imei ) AND booking_status = 13;
    select trip_dst_area_id into @pr_dest_no from tbl_trip where pnr_id = @pr_pnr_no order by trip_id desc limit 0,1;
    update tbl_taxi set taxi_cur_status = 12,taxi_cur_area = @pr_dest_no where taxi_id = NEW.gps_cab_bus;
    update tbl_booking set booking_status = 9 where booking_pnr_no = @pr_pnr_no;
    END;
    END IF;
    IF @cab_meter_new = 0 and @cab_meter_old = 1 THEN//break IF into separate IF 
    BEGIN
    select `booking_pnr_no` into @pr_pnr_no from tbl_booking where booking_alloted_vehicle = (select taxi_id from tbl_taxi where taxi_imei = NEW.gps_imei ) AND booking_status = 9;
    select trip_dst_area_id into @pr_dest_no from tbl_trip where pnr_id = @pr_pnr_no order by trip_id desc limit 0,1;
    update tbl_taxi set taxi_cur_status = 10,taxi_cur_area = @pr_dest_no where taxi_id = NEW.gps_cab_bus;
    update tbl_booking set booking_status = 8 where booking_pnr_no = @pr_pnr_no;
    END;
    END IF;
    END; //
    delimiter ;
于 2013-01-19T07:46:59.887 に答える
0

の後にセミコロンの入力を間違えましたEND IF

于 2013-01-19T07:25:34.727 に答える