0% found this document useful (0 votes)
12 views

Then Then IF IF: Example

Uploaded by

Irwan Fath
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Then Then IF IF: Example

Uploaded by

Irwan Fath
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Syntax:

IF search_condition THEN statement_list


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

The IF statement for stored programs implements a basic conditional


construct.

*Note*: There is also an IF() function, which differs from the IF


statement described here. See
https://mariadb.com/kb/en/if-function/. The
IF statement can have THEN, ELSE, and ELSEIF clauses, and it is
terminated with END IF.

If the search_condition evaluates to true, the corresponding THEN or


ELSEIF clause statement_list executes. If no search_condition matches,
the ELSE clause statement_list executes.

Each statement_list consists of one or more SQL statements; an empty


statement_list is not permitted.

URL: https://mariadb.com/kb/en/if-statement/

Syntax:
[begin_label:] BEGIN
[statement_list]
END [end_label]

[begin_label:] LOOP
statement_list
END LOOP [end_label]

[begin_label:] REPEAT
statement_list
UNTIL search_condition
END REPEAT [end_label]

[begin_label:] WHILE search_condition DO


statement_list
END WHILE [end_label]

Labels are permitted for BEGIN ... END blocks and for the LOOP, REPEAT,
and WHILE statements. Label use for those statements follows these
rules:

o begin_label must be followed by a colon.

o begin_label can be given without end_label. If end_label is present,


it must be the same as begin_label.

o end_label cannot be given without begin_label.

o Labels at the same nesting level must be distinct.

o Labels can be up to 16 characters long.

To refer to a label within the labeled construct, use an ITERATE or


LEAVE statement. The following example uses those statements to
continue iterating or terminate the loop:

CREATE PROCEDURE doiterate(p1 INT)


BEGIN
label1: LOOP
SET p1 = p1 + 1;
IF p1 < 10 THEN ITERATE label1; END IF;
LEAVE label1;
END LOOP label1;
END;

The scope of a block label does not include the code for handlers
declared within the block. For details, see [HELP DECLARE HANDLER].

URL: https://mariadb.com/kb/en/labels/

You might also like