Home > Database > Mysql Tutorial > MySQL Advanced II - Process Control Statement

MySQL Advanced II - Process Control Statement

黄舟
Release: 2016-12-29 16:29:49
Original
1435 people have browsed it

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
$$;
Copy after login

Modify the mysql end character;

delimiter ;
Copy after login

Set a variable;

set @age = 19;
Copy after login
Call the p_showage method;
call p_showage(@age);
Copy after login
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
$$;
Copy after login

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;
$$;
Copy after login

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)!


source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template