MySQL syntax-error in nested loop block. Can't find the error. -
i tried code simple nested loop mysql block. server got me syntax error, can't find it.
does see it?
the error message was: query: end loop get_invoice
error code: 1064 have error in sql syntax; check manual corresponds mysql server version right syntax use near 'end loop get_invoice' @ line 1
begin declare v_id int default 0; declare v_finished1 int default 0; declare invoices_cursor cursor select id_invoice invoice invoice_type = 're' , exists (select 1 invoice ma invoice_type = 'ma' , ma.origin = i.id_invoice); declare continue handler not found set v_finished1 = 1; open invoices_cursor; get_invoice: loop fetch invoices_cursor v_id; if v_finished1 = 1 close invoices_cursor; leave get_invoice; end if; declare v_finished2 int default 0; declare v_dunning_level int default 1; declare dunning_cursor cursor select id_invoice invoice ma invoice_type = 'ma' , ma.origin = v_id order `create` asc; declare continue handler not found set v_finished2 = 1; open dunning_cursor; get_dunnings: loop declare v_id_dun bigint default null; fetch dunning_cursor v_id_dun; if v_finished = 1 leave get_dunnings; end if; update invoice set dunning_level = v_dunning_level invoice_type = 'ma' , id_invoice = v_id_dun; set v_dunning_level = v_dunning_level + 1; end loop get_dunnings ; close dunning_cursor; end loop get_invoice ; end;
Comments
Post a Comment