declaring variable inside mysql stored procedure -


we trying declare variable inside mysql stored procedure has transaction implemented in it. seems giving syntax error :

following syntax of stored procedure:

create procedure `sp_markappointmentrefferal`(   p_appid bigint,   p_newlocation bigint,   p_userid bigint,   p_referralreason varchar(500),   p_newlocationname varchar(100) ) begin   declare v_oldlocation int default 0; set v_oldlocation = (select locationid appointments iappid = p_appid limit 1 );   declare exit handler sqlexception      begin         rollback;         select -1;     end;     start transaction;         update table set is_referred = 1,  referred_timestamp = now(),   referral_reason = p_referralreason  iappid = p_appid  limit 1;    -- create new appointment new referred location..    insert appointments   (vappname, vapptype, dappdate, vcell, ipatid, iappstatus, iuserid, iactive,    dinsertdate, ihsid, daily_ticket_no, locationid, visit_id, encounter_id, referredfrom,referredopdname, opd_name )      select vappname, vapptype, now(), vcell, ipatid, iappstatus, p_userid,      1, now(), ihsid, fn_generatenextappointmentticket(now(),p_newlocation) , p_newlocation, visit_id, encounter_id+1,      (select locationid appointments iappid = p_appid limit 1),     (select opd_name appointments iappid = p_appid limit 1), p_newlocationname     appointments     iappid = p_appid limit 1;      select last_insert_id();  commit;    end; 

the syntax checker saying declare command not valid here. have tried place inside transaction clause , similar error shows ..

any appreciated..

all declare statements should @ top of stored procedure body. moving declare exit handler before set statement should fix problem.


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -