stored procedures - MySQL Function getting Syntax Error -
i trying create below function in mysql getting syntax error. not able find solution, grateful help
create function `test`.`pro`(depart_id int) returns varchar begin declare title varchar; if depart_id = 1 set title='it department'; else if depart_id = 2 set title='hr department'; else set title='admin'; end if; return title; end$$ delimiter ;
you have several syntax errors in script:
varchar
must have length- you should define
delimiter $$
first - it's not
else if
,elseif
try this;)
delimiter $$ create function `test`.`pro`(depart_id int) returns varchar(10) begin declare title varchar(10); if depart_id = 1 set title='it department'; elseif depart_id = 2 set title='hr department'; else set title='admin'; end if; return title; end $$ delimiter ;
Comments
Post a Comment