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

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -