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

The MySQL LEAVE statement is used within the context of a stored program (such as a stored procedure, function, or trigger) to exit the program prematurely. It provides a way to terminate the execution of a program block and return control...

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...