Links to control Mysql procedures: Mysql Installation http://www.bkjia.com/database/201210/162314.html Mysql (2) Database Operations http://www.bkjia.com/database/201210/162315.html Mysql (3) operations on Data Tables http://www.bkjia.com/database/201210/162316.html Mysql (4) Data Table query operations http://www.bkjia.com/database/201210/162317.html Mysql (5) operation time http://www.bkjia.com/database/201210/162318.html;Mysql Those things (6) String Pattern Matching http://www.bkjia.com/database/201210/163969.html;Mysql Those things (7) In-depth select query http://www.bkjia.com/database/201210/163970.html;Mysql Those things (8) Index http://www.bkjia.com/database/201210/163971.html Mysql (9) common functions http://www.bkjia.com/database/201210/164229.html Mysql (10) trigger 1 http://www.bkjia.com/database/201210/164516.html Mysql (11) trigger 2 http://www.bkjia.com/database/201210/164766.html Mysql stored procedures http://www.bkjia.com/database/201210/164795.html Mysql (13) usage of variables and conditions http://www.bkjia.com/database/201211/165662.html Mysql (14) usage of the cursor http://www.bkjia.com/database/201211/165664.html IF statement www.2cto.com 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; SQL code of CASE statements --- syntax format of CASE statements CASE case_value when_value THEN statement_list [WHEN when_value THEN statement_list]... [ELSE statement_list] end case www. 2cto.com --- Example of the 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 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; the SQL code of the ITERATE statement 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/222) = 0 THEN iterate ins; end if; insert into actor (first_name, last_name) VALUES ('test',); end loop ins; END; $ delimiter; SQL code of the REPEAT statement-conditional loop. when conditions are met, the statement exits. -- Syntax: [begin_label:] REPEAT statement_list UNTIL search_condition end repeat [end_label] -- Example repeat fetch cur_payment INTO limit, d_amount; if Limit = 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]