Home > Database > Mysql Tutorial > MySQL Advanced 3 - Loop Statement

MySQL Advanced 3 - Loop Statement

黄舟
Release: 2016-12-29 16:31:13
Original
1426 people have browsed it

1. Where loop

create procedure p_addnum()
begin
declare i int default 1;
declare addresult int default 0;
while i <= 100 do
	set addresult = addresult + i;
	set i = i + 1;
end while;
select addresult;
end;
$$;
Copy after login

2. Repeat loop

create procedure p_updatenum()
begin
declare imin int default 1;
declare value int default 1;
declare imax int default 100;
repeat
	select value;
	set value = value + 1;
	set imin = imin + 1;
	until imin > imax
end repeat;
end;
$$;
Copy after login

3. Loop loop

create procedure p_updateloop()
begin
declare imin int default 1;
declare value int default 1;
declare imax int default 100;
myloop:loop
	select value;
	set value = value + 1;
	set imin = imin + 1;
	if imin > imax then
	leave myloop;
	end if;
end loop;
end;
$$;
Copy after login

The above is the content of MySQL Advanced Three - Loop Statement, more For related content, please pay attention to the PHP Chinese website (www.php.cn)!


Related labels:
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