Category: MySQL

MySQL Loop

MySQL Loop MySQL Loop syntax and example. MySQL Loop syntax [ begin_label: ] LOOP statement_list END LOOP [ end_label ] Loop example CREATE PROCEDURE loop_proc(x INT) BEGIN DECLARE p_output VARCHAR(50); SET p_output = ''; loop_label: LOOP SET p_output = CONCAT(p_output,x,','); SET...

MySQL Leave

MySQL Leave Leave statement is used to exit the flow control construct that has the given label. MySQL Leave syntax and example. Leave example CREATE PROCEDURE leave_proc(a INT) BEGIN p_label: LOOP SET a = a + 1; IF a < 3...

MySQL Iterate

MySQL Iterate Iterate means that mysql loop can start again. MySQL Iterate syntax and example. Iterate example CREATE PROCEDURE iterate_proc(x INT) BEGIN p_label: LOOP SET x = x + 1; IF x < 5 THEN ITERATE p_label; END IF; LEAVE p_label;...

MySQL IF

MySQL IF MySQL IF syntax and example. MySQL IF syntax IF search_condition THEN statement_list [ELSEIF search_condition THEN statement_list] … [ELSE statement_list] END IF IF example CREATE OR REPLACE FUNCTION if_test(p_id int) RETURNS TEXT BEGIN DECLARE v_return TEXT; IF p_id=1 THEN SET...

MySQL Case

MySQL Case MySQL Case syntax and example. MySQL CASE syntax CASE case_value WHEN when_value THEN statement_list [WHEN when_value THEN statement_list] … [ELSE statement_list] END CASE CASE WHEN search_condition THEN statement_list [WHEN search_condition THEN statement_list] … [ELSE statement_list] END CASE Case example...