Search code examples
mysqlmariadbprocedure

What is the matter with if statement in procedure?


It is simple to write a sql procedure.

demiliter //
create procedure show_growth()
begin
SELECT * from tb;
end //

I want to add a if statement in the procedure.
Drop it first.

 drop procedure show_growth //

Then create a new one.

create procedure show_growth(in type char(3))
    -> begin
    -> if type = "all" then 
    -> SELECT * from tb;
    -> endif
    -> end //

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'end' at line 6

How to fix it?


Solution

  • endif is not 1 word.

     begin
       if type = "all" then    
        SELECT * from tb;
       end if;
     end