1. MySQL process control statement - selection statement
1. There is only one judgment
delimiter $$; create procedure p_showage(in age int) begin if age >= 18 then select '成年人'; else select '未成年人'; end if; end $$;
Modify the mysql end character;
delimiter ;
Set a variable;
set @age = 19;
call p_showage(@age);
delimiter $$; create procedure p_showagetwo(in age int) begin if age >= 18 && age < 60 then select '成年人'; elseif age >= 60 then select '老年人'; else select '未成年人'; end if; end $$;
2. MySQL process control statement-case control statement
create procedure p_addsaloary(in v_empno int) begin declare adds int; case v_empno when 1 then set adds = 1; when 2 then set adds = 2; when 3 then set adds = 3; else set adds = 4; end case; update test set age = adds where id = v_empno; end; $$;
ifnull(exp1,exp2) determines whether it is a null value. It has two parameters.
If the first expression is a null value, output the second value.
If the first expression The expression is not empty, and the first value is output
The above is the content of MySQL Advanced 2 - Process Control Statement. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!