jeudi 26 août 2021

IF THEN ELSE MariaDb

I'm trying to write a simple 'IF' statement on MariaDb but I stumbled on the basics.

This is my code:

SELECT @variable := `value` FROM configuration WHERE key = 'key' 

this seems to work, but can a variable declared in this way be used in a if ?

IF @variable = "foo" THEN
    UPDATE ...
    UPDATE ...
    DELETE ...
ELSE
    UPDATE ...
END IF;

I'm forced to put this code only in a procedure ? Most of the code I read put all this inside a procedure but in the official documentation here there is nothing about it.

When I try to run this script inside phpMyAdmin I get:

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 'IF @variable = "foo" THEN
    UPDATE tags SET .... 

Aucun commentaire:

Enregistrer un commentaire