jeudi 3 septembre 2015

mysql if without select

I'm using mysql and I want to use the if statement in a way you are doing in a stored procedure. Something like this:

delimiter $$

  if @myVariable is null then
    drop temporary table tmp_buffer;
    select 'cannot proceed without variable @myVariable';
  else
    update my_table as t
    set t.name = @myVariable;
  end;

end$$

delimiter ;

When I execute this code it does nothing. I tried to google this but I only find select if(....) explanations what doesn’t fit to my requirements. I know that it is possible to create a stored procedure and put the code there and then call the procedure, but I'm looking for a way to do it without stored procedures. Is this possible? If yes, what is wrong in my code?

Thanks for reading this

Felix

Aucun commentaire:

Enregistrer un commentaire