I test sql querys.
IF 3 = 3 THEN
SELECT 'TRUE'
ELSE
SELECT 'FALSE'
END IF;
I excuted that query on SQLyog.
I got the error message below.
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 'ELSE SELECT
'FALSE' END IF' at line 3
That query is very simple. I don't know why happen error message.
The \W command will show warnings after every statement, while \w will disable this. Starting the client with the --show-warnings option will show warnings after every statement. MariaDB 10.3.
In MariaDB, the IF-THEN-ELSE statement is used to execute code when a condition is TRUE, or execute different code if the condition evaluates to FALSE.
Introduction to MariaDB is null operatorThe is null returns true if the expression is null ; otherwise, it returns false . Note that in MariaDB, a value of 0 is considered false and non-zero values considered true . The expression returns true if the value is not null; otherwise, it returns false .
IF
itself is not a query, it cannot be executed as a standalone statement.
There are two different IF
s that you can use.
One is the conditional construct in compound statements. It can be used in stored routines:
DELIMITER $
CREATE PROCEDURE pr()
BEGIN
IF 3 = 3 THEN
SELECT 'TRUE';
ELSE
SELECT 'FALSE';
END IF;
END $
DELIMITER ;
CALL pr;
Or, if you are running a reasonably new version of MariaDB (10.1+), you can also use it in an anonymous block:
DELIMITER $
BEGIN NOT ATOMIC
IF 3 = 3 THEN
SELECT 'TRUE';
ELSE
SELECT 'FALSE';
END IF;
END $
DELIMITER ;
Another is the IF
function, which can be used inside a query:
SELECT IF(3 = 3 THEN 'TRUE','FALSE');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With