Ayoub EL Abassi
Ayoub EL Abassi

Reputation: 41

Mysql if statement doesn't work

I'm trying to add a stored procedure into Mysql but always shows an error in line 6 Please help me to fix this problem.

create procedure User_Sync_Proc(in ID int,in Matricule int,in Type_OP nvarchar(50))
begin
    if (select current_user()='root@localhost')
    then
        insert into user_sync values(ID,Matricule,Type_OP,Now());
    end if;
end

Upvotes: 1

Views: 63

Answers (1)

P.Salmon
P.Salmon

Reputation: 17640

You may just need to set delimiters

drop procedure if  exists User_Sync_Proc;

delimiter $$

create procedure User_Sync_Proc(in ID int,in Matricule int,in Type_OP nvarchar(50))
begin
    if (select current_user()='root@localhost')
    then
        insert into user_sync values(ID,Matricule,Type_OP,Now());
    end if;
end $$

delimiter ;

Upvotes: 1

Related Questions