请教:关于循环的控制问题!谢谢!

[复制链接]
查看11 | 回复8 | 2007-8-9 20:13:55 | 显示全部楼层 |阅读模式
请问:在循环中,如果满足条件时,直接进入下一条循环的命令怎么写??就是红色字体那里!谢谢!
declare
i number :=1;
begin
for i in 1..10 loop
if i7 then
next record;[/COLOR]
else
dbms_output.put_line(i);
end if;
end loop;
end
回复

使用道具 举报

千问 | 2007-8-9 20:13:55 | 显示全部楼层
用CONTINUE报错:
ORA-06550: line 6, column 3:
PLS-00201: identifier 'CONTINUE' must be declared
ORA-06550: line 6, column 3:
PL/SQL: Statement ignored
用RETURN,直接退出,
该用什么呢??
回复

使用道具 举报

千问 | 2007-8-9 20:13:55 | 显示全部楼层
1declare
2i number :=1;
3begin
4for i in 1..10 loop
5if i7 then
6goto label1;
7else
8dbms_output.put_line(i);
9end if;
10>
11null;
12end loop;
13* end;
[email protected]> /
7
PL/SQL procedure successfully completed.
在那个标记后面要加一个NULL!
其实不推荐这么用的,用goto是不好的习惯
回复

使用道具 举报

千问 | 2007-8-9 20:13:55 | 显示全部楼层
最初由 lwxxrq 发布
[B]1declare
2i number :=1;
3begin
4for i in 1..10 loop
5if i7 then
6goto label1;
7else
8dbms_output.put_line(i);
9end if;
10>
11null;
12end loop;
13* end;
[email protected]> /
7
PL/SQL procedure successfully completed.
在那个标记后面要加一个NULL!
其实不推荐这么用的,用goto是不好的习惯 [/B]


谢谢你的帮助!我的意思是应该有个类似于:continue的命令来控制循环的!可是好像没有!goto可以是可以,不过不推荐使用阿!
我是在if ....then后面用的null;来使其不做动作的,但是还是要把下面的运行完,才能进入下一条循环的, 这部分完全可以不判断的!
没办法,那就用null吧,谢谢你!
回复

使用道具 举报

千问 | 2007-8-9 20:13:55 | 显示全部楼层
CREATE OR REPLACE procedure mytestP as
i number :=1;
begin
for i in 1..10 loop
if i7 then
goto lab;
else
dbms_output.put_line(i);
end if;
>
null;
end loop;
end mytestP;

为什么>后面要有:null;才可以编译通过?
回复

使用道具 举报

千问 | 2007-8-9 20:13:55 | 显示全部楼层
因为后面不能直接跟着end啊,所以加了一个null。
回复

使用道具 举报

千问 | 2007-8-9 20:13:55 | 显示全部楼层
其实我经常写这种程序的时候主要是把逻辑反过来,取消ELSE 子句,因为GOTO语句很容易跳得晕头转向,把格式弄好一点就可以了。
FOR ncount 1..100 LOOP
IF() THEN
DBMS_OUTPUT.PUTLINE('');

END IF;
END LOOP;
回复

使用道具 举报

千问 | 2007-8-9 20:13:55 | 显示全部楼层
最初由 zhpsam 发布
[B]CREATE OR REPLACE procedure mytestP as
i number :=1;
begin
for i in 1..10 loop
if i7 then
goto lab;
else
dbms_output.put_line(i);
end if;
>
null;
end loop;
end mytestP;

为什么>后面要有:null;才可以编译通过? [/B]


for i in 1..10 loop
if i7 then
null;
else
dbms_output.put_line(i);
end if;
end loop;
直接这样就可以呀!
回复

使用道具 举报

千问 | 2007-8-9 20:13:55 | 显示全部楼层
另一办法: 定义异常
declare
i number :=1;
val_exp exception;
begin
for i in 1..10 loop
begin
if i7 then
raise val_exp;
else
dbms_output.put_line(i);
end if;
exception when val_exp then null;
end;
end loop;
end
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行