Category Archives: MySQL

MySQL Tutorial

MySQL

MySQL Tutorial is an fast way to learn mysql language with examples for beginners developers. On this course you can learn about MySQL language using this mysql tutorial based on simple and complex examples. MySQL language is a widely used relational database management based on SQL language. The main sections of MySQL language are: Database Data Types Clauses… Read More »

MySQL While

MySQL While MySQL While syntax and example. The WHILE statement is repeated as long as the condition expression is true. MySQL While syntax [ begin_label: ] WHILE condition DO mysql_code END WHILE [ end_label ] While example CREATE PROCEDURE while_proc(x int) BEGIN DECLARE i INT DEFAULT 0; DECLARE y INT; SET y = x; WHILE y > 0… Read More »

MySQL Return

MySQL Return MySQL Return syntax and example. The RETURN statement terminates execution of a stored function and returns the value expr to the function caller. Return example CREATE FUNCTION return_value(x INT) RETURNS TEXT BEGIN IF x=1 THEN RETURN ‘OK’; ELSE RETURN ‘NOK’; END IF; END; SELECT return_value(1); Output FUNCTION RETURN_VALUE compiled OK

MySQL Repeat

MySQL Repeat MySQL Repeat syntax and example. The statement list within a REPEAT statement is repeated until the search_condition expression is true. MySQL Repeat syntax [ begin_label: ] REPEAT statement_list UNTIL search_condition END REPEAT [ end_label ] Repeat example CREATE PROCEDURE repeat_proc(x INT) BEGIN DECLARE total INT; SET total = 0; REPEAT SET total = total + 1;… Read More »

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 x = x + 1; IF x

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 THEN ITERATE p_label; END IF; LEAVE p_label; END LOOP p_label; SET @b = a; END; Output PROCEDURE… Read More »

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; END LOOP p_label; SET @x = x; END; Output PROCEDURE ITERATE_PROC compiled

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 v_return = ‘ABC’; ELSEIF p_id=2 THEN SET v_return = ‘XYZ’; ELSE SET v_return=’N/A’; END IF; RETURN v_return;… Read More »

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 CREATE OR REPLACE FUNCTION case_test(p_id int) RETURNS TEXT BEGIN DECLARE v_name TEXT; CASE p_id WHEN 1 THEN… Read More »