1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
---关于Oracle里面的循环
--
while
循环
CREATE OR REPLACE
function while_test(x in number,y in number)
return
number is
z number;
totalCount number;
begin
z:=x;
totalCount:=
0
;
while
z<y+
1
loop
delete USERTEMP where id=z;
z:=z+
1
;
totalCount:=totalCount+
1
;
end loop;
return
totalCount; --结果为
6
end;
--
for
循环
CREATE OR REPLACE
function for_test(x in number)
return
number is
z number;
begin
z:=
0
;
for
v_sum in
1
..
50
loop
z:=z+
2
;
end loop;
return
z;
end;
--单循环
CREATE OR REPLACE
function perfunctory_test(x in number)
return
number
is z number;
begin
loop
z:=x*x; --实现函数(x)的平方
exit;
end loop;
return
z;
end;
--- 注意事项 :mysql 里面的循环和Oracle里面的不一样,声明,赋值都不一样。这里吃了大亏,自己一直在写MySQL的语句,所以运行不成功。
-- 【Mysql】的
while
循环语句
declare
@i
int
set
@i
=
1
while
@i
<
10
begin
insert into USERTEMP(id,name,CARDTYPE,CARDNO,status) VALUES(
@i
,
'李'
,
'学生'
,
'01'
,
2
);
set
@i
=
@i
+
1
end
|
本文转自建波李 51CTO博客,原文链接:http://blog.51cto.com/jianboli/1898729,如需转载请自行联系原作者