Home  >  Article  >  Database  >  MySQL Advanced II - Process Control Statement

MySQL Advanced II - Process Control Statement

黄舟
黄舟Original
2016-12-29 16:29:491354browse

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 the p_showage method;
call p_showage(@age);
2. Contains two judgments
delimiter $$;
create procedure p_showagetwo(in age int)
begin
if age >= 18 && age < 60 then
  select &#39;成年人&#39;;
elseif age >= 60 then
  select &#39;老年人&#39;;
else
  select &#39;未成年人&#39;;
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)!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:MySQL Advanced 1Next article:MySQL Advanced 1