Mysql (15) process control _ MySQL

Source: Internet
Author: User
Tags mysql index
Mysql (15th) process control bitsCN.com


Mysql (15) process control

Related links:

Mysql (1) installation of mysql

Http: // database/201210/162314 .html;

Mysql-related operations (2)

Http: // database/201210/162315 .html;

Mysql operations on data tables (3)

Http: // database/201210/162316 .html;

Mysql (4) Data Table query operations

Http: // database/201210/162317 .html;

Mysql operations (5)

Http: // database/201210/162318 .html;

Mysql (6) string pattern matching

Http: // database/201210/163969 .html;

Mysql (7) in-depth select query

Http: // database/201210/163970 .html;

Mysql Index (8)

Http: // database/201210/163971 .html;

Mysql common functions

Http: // database/201210/164229 .html;

Mysql (10) trigger 1

Http: // database/201210/164516 .html;

Mysql things (11) trigger 2

Http: // database/201210/164766 .html;

Mysql stored procedures

Http: // database/201210/164795 .html;

Mysql (13) usage of variables and conditions

Http: // database/201211/165662 .html;

Mysql usage of those things (14) cursor

Http: // database/201211/165664 .html

IF statement

SQL code

--- Syntax structure

IF search_condition THEN statement_list

[ELSEIF search_condition THEN statement_list]...

[ELSE statement_list]

END IF

--- Example

If I _staff_id = 2 then

Set @ x1 = @ x1 + d_amount;

Else

Set @ x2 = @ x2 + d_amount;

End if;

CASE Statement

SQL code

--- Syntax format of the CASE statement

CASE case_value

WHEN when_value THEN statement_list

[WHEN when_value THEN statement_list]...

[ELSE statement_list]

END CASE

--- Example of case statement:

Case

When I _staff_id = 2 then

Set @ x1 = @ x1 + d_amount;

Else

Set @ x2 = @ x2 + d_amount;

End case

LOOP statement

SQL code

[Begin_label:] LOOP

Statement_list

End loop [end_label]

--- If you do not add an exit LOOP statement in statement_list, the LOOP statement can be used to implement a simple endless LOOP.

LEAVE statement

SQL code

--- Replace the Terminator with $

Delimiter $

--- Create a stored procedure

Create procedure actor_num ()

BEGIN

Set @ x = 0;

Ins: LOOP

Set @ x = @ x + 1;

IF @ x = 100 THEN

Leave ins;

End if;

Insert into actor (first_name, last_name) VALUES ('test', 222 );

End loop ins;

END;

$

Delimiter;

ITERATE statement

SQL code

-- It must be used in a loop to skip the current loop and directly enter the next loop.

Delimiter $

Create procedure actor_num ()

BEGIN

Set @ x = 0;

Ins: LOOP

Set @ x = @ x + 1;

IF @ x = 100 THEN

Leave ins;

ELSEIF mod (@ x/2, 0) = 0 THEN

Iterate ins;

End if;

Insert into actor (first_name, last_name) VALUES ('test', 222 );

End loop ins;

END;

$

Delimiter;

REPEAT statement

SQL code

-- Conditional loop: exit the loop when conditions are met.

-- Syntax:

[Begin_label:] REPEAT

Statement_list

UNTIL search_condition

End repeat [end_label]

-- Example

REPEAT

FETCH cur_payment INTO I _staff_id, d_amount;

If I _staff_id = 2 then

Set @ x1 = @ x1 + d_amount;

Else

Set @ x2 = @ x2 + d_amount;

End if;

UNTIL 0 end repeat;

WHILE statement

SQL code

--- Syntax structure

[Begin_label:] WHILE search_condition DO

Statement_list

End while [end_label]

BitsCN.com

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.