oracle存储过程循环怎么写
mip版 关注:173 答案:2 悬赏:40
解决时间 2021-01-18 03:33
已解决
2021-01-18 00:13
oracle存储过程循环怎么写
最佳答案
2021-01-18 01:04
Oracle中有三种循环(For、While、Loop):
1、loop循环:
create or replace procedure pro_test_loop is
i number;
begin
i:=0;
loop
i:=i+1;
dbms_output.put_line(i);
if i>5 then
exit;
end if;
end loop;
end pro_test_loop;
2、while循环:
create or replace procedure pro_test_loop is
i number;
begin
i:=0;
while i<5 loop
i:=i+1;
dbms_output.put_line(i);
end loop;
end pro_test_loop ;
3、for循环1:
create or replace procedure pro_test_for is
i number;
begin
i:=0;
for i in 1..5 loop
dbms_output.put_line(i);
end loop;
end pro_test_for;
4、for循环2:
create or replace procedure pro_test_cursor is
userRow t_user%rowtype;
cursor userRows is
select * from t_user;
begin
for userRow in userRows loop
dbms_output.put_line(userRow.Id||','||userRow.Name||','||userRows%rowcount);
end loop;
end pro_test_cursor;
全部回答
1楼
2021-01-18 01:35
oracle中有三种循环(for、while、loop):
1、loop循环:
create or replace procedure pro_test_loop is
i number;
begin
i:=0;
loop
i:=i+1;
dbms_output.put_line(i);
if i>5 then
exit;
end if;
end loop;
end pro_test_loop;
2、while循环:
create or replace procedure pro_test_loop is
i number;
begin
i:=0;
while i<5 loop
i:=i+1;
dbms_output.put_line(i);
end loop;
end pro_test_loop;
3、for循环1:
create or replace procedure pro_test_for is
i number;
begin
i:=0;
for i in 1..5 loop
dbms_output.put_line(i);
end loop;
end pro_test_for;4、for循环2:
create or replace procedure pro_test_cursor is
userrow t_user%rowtype;
cursor userrows is
select * from t_user;
begin
for userrow in userrows loop
dbms_output.put_line(userrow.id||','||userrow.name||','||userrows%rowcount);
end loop;
end pro_test_cursor;
我要举报
如果感觉以上信息为低俗/不良/侵权的信息,可以点下面链接进行举报,我们会做出相应处理,感谢你的支持!
点此我要举报以上信息!
推荐资讯
大家都在看