database - Mysql Trigger Explicit Implicit Command Not allowed -
i m trying create trigger showing "explicit , implicit command not allowed". have tried refer other topics here i'm not clear. trigger code.
use `vms`; delimiter $$ create trigger `trg_bookingdetails` after insert on `bookingdetails` each row begin declare int default 1; declare v_ga int default 0; declare v_bid varchar(20); declare v_bdate date; declare v_sdate date; declare v_sid varchar(20); declare v_bcode varchar(10); declare v_q int; declare v_vid int; declare v_jj int; declare v_ss int; declare v_mj int; create temporary table if not exists temp_boo ( `bid` varchar(50) null default null, `bdate` date null default null, `sdate` date null default null, `sid` varchar(20) null default null, `bcode` varchar(20) null default null, `vid` varchar(20) null default null ); begin select bm.bid,bm.bdate,bm.sdate,bm.sid,bd.bcode, bd.quantity v_bid,v_bdate,v_sdate,v_sid,v_bcode,v_ga bookingmaster bm, bookingdetails bd bm.sdate=new.sdate , bm.bid=bd.bid , bd.bcode='gap' , bm.bid=new.bid; end; while (i<=v_ga) insert temp_boo(bid,bdate,sdate,sid,bcode) values(new.bid,new.bdate,new.sdate,new.sid,new.bcode); set i=i+1; end while; set i=1; begin select bm.bid,bm.bdate,bm.sdate,bm.sid,bd.bcode, bd.quantity v_bid,v_bdate,v_sdate,v_sid,v_bcode,v_jj bookingmaster bm, bookingdetails bd bm.sdate=new.sdate , bm.bid=bd.bid , bd.bcode='jjp' , bm.bid=new.bid; end; while (i<=v_jj) insert temp_boo(bid,bdate,sdate,sid,bcode) values(new.bid,new.bdate,new.sdate,new.sid,new.bcode); set i=i+1; end while; set i=1; begin select bm.bid,bm.bdate,bm.sdate,bm.sid,bd.bcode, bd.quantity v_bid,v_bdate,v_sdate,v_sid,v_bcode,v_ss bookingmaster bm, bookingdetails bd bm.sdate=new.sdate , bm.bid=bd.bid , bd.bcode='ssp' , bm.bid=new.bid; end; while (i<=v_ss) start transaction; insert temp_boo(bid,bdate,sdate,sid,bcode) values(new.bid,new.bdate,new.sdate,new.sid,new.bcode); set i=i+1; end while; set i=1; begin select bm.bid,bm.bdate,bm.sdate,bm.sid,bd.bcode, bd.quantity v_bid,v_bdate,v_sdate,v_sid,v_bcode,v_mj bookingmaster bm, bookingdetails bd bm.sdate=new.sdate , bm.bid=bd.bid , bd.bcode='mjp' , bm.bid=new.bid; end; while (i<=v_mj) insert temp_boo(bid,bdate,sdate,sid,bcode) values(new.bid,new.bdate,new.sdate,new.sid,new.bcode); set i=i+1; end while; insert bookinguser (bid,bdate,sdate,sid,bcode) (select bid,bdate,sdate,sid,bcode temp_boo (bid,bdate,sdate,sid,bcode) not in (select bid,bdate,sdate,sid,bcode bookinguser)); drop table temp_boo; end
please let me know m doing mistake.
try this:
... while (i<=v_ss) /*start transaction;*/ insert temp_boo(bid,bdate,sdate,sid,bcode) values(new.bid,new.bdate,new.sdate,new.sid,new.bcode); set i=i+1; end while; ...
update
you can not use drop table inside trigger. see 13.3.3 statements cause implicit commit.
... insert bookinguser (bid,bdate,sdate,sid,bcode) (select bid,bdate,sdate,sid,bcode temp_boo (bid,bdate,sdate,sid,bcode) not in (select bid,bdate,sdate,sid,bcode bookinguser)); /*drop table temp_boo;*/ ...
update 1
a better approach is:
13.3.3 statements cause implicit commit
"create table , drop table statements not commit transaction if temporary keyword used.".
... while (i<=v_ss) /*start transaction;*/ insert temp_boo(bid,bdate,sdate,sid,bcode) values(new.bid,new.bdate,new.sdate,new.sid,new.bcode); set i=i+1; end while; ... insert bookinguser (bid,bdate,sdate,sid,bcode) (select bid,bdate,sdate,sid,bcode temp_boo (bid,bdate,sdate,sid,bcode) not in (select bid,bdate,sdate,sid,bcode bookinguser)); drop temporary table temp_boo; ...
Comments
Post a Comment