IF THEN ELSE with Multiple statements

According to the online docs - it shows:

IF search_condition THEN statement_list
    [ELSEIF search_condition THEN statement_list] ...
    [ELSE statement_list]

However - at least in my stored procedures - it appears that only the first statement in the "statement_list" executes. I remedies this by putting a BEGIN ... END; that started after the IF (or THEN, to be more specific) and ended just before the ELSE/END IF. This doesn't seem to be the behavior of the CASE structures I have in other stored procedures (more possible conditions, made more sense than IF/ELSE or nested IF's to me).

Is this the expected behavior?

I haven't had a chance to review all of my stored procedures to see if I have any with multiple statements in the "statement_list" of any IF structures - but - I will take some time to see if I have any - and specifically test for any conditions that would hit sections with more than one statement in the statement_list.

My environment is MariaDB installed on a VICIdial / VICIbox system, MariaDB's version variable is showing a value of "10.1.6-MariaDB-log"

I prefer to be explicit when I program - so - including a BEGIN ... END; for clarity doesn't bother me at all - and - it's also useful for ELSE situations where I don't really want to run any statements - so - it would be consistent to always use it - but - just wasn't expecting this behavior at all.

Thanks for any feedback / confirmation of what I am seeing...David


Comments loading...
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.