mysql - Transaction or variable declaration error -


i started learning transactions , stored procedures , i'm trying myself familiar different ways of assigning values result set variables.

what causing error on declare var_curcid int default 0;

here's i've done far.

create definer=`root`@`localhost` procedure `addcurriculumwithschoolyear`(in p_subjectname varchar(50), in p_yrlevel varchar(30), in p_desc text, in p_creator varchar(20)) begin      declare haserror bool default 0;     declare continue handler sqlexception set haserror = 1;      declare var_curcid int default 0;      declare var_systart int default 0;     declare var_syend int default 0;          start transaction;          -- 1 insert statement curriculum table             insert curriculum(`name`,`yearlevel`,`description`,`creator`)             values(p_subjectname,p_yrlevel,p_desc,p_creator);         -- 2 insert statement schoolyearcurriculum table              insert schoolyearcurriculums(curriculumid,systart,syend)             values(var_curcid,var_systart,var_syend);          if `haserror`             rollback; -- if error occurs of insert, select statements above, undo         else              commit; -- if insert, select statement successful, execute.             select 'successfully inserted information';         end if; end; 

the erorr on declaration of var_curcid variable saying syntax error: unexpected 'var_curcid' (identifier)

i'm new hope can me. i'm still trying different ways such using := operator , select into , set.

i'd appreciate help.

thanks.

this bit tricky. put declarations before handler:

create procedure `addcurriculumwithschoolyear`(in p_subjectname varchar(50), in p_yrlevel varchar(30), in p_desc text, in p_creator varchar(20)) begin       declare haserror bool default 0;     declare var_curcid int default 0;      declare var_systart int default 0;     declare var_syend int default 0;      declare continue handler sqlexception set haserror = 1;  end 

here sql fiddle.

in begin/end block, declares must first statements. handler after variable declarations; didn't realize required, however, until testing it.


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -