请问oracle存储过程中,循环的时候有没有像JAVA那种continue 功能

oodick 2010-03-10 01:12:32
RT,
存储过程有没有类似java ,当遇到一定的条件的时候,我需要退出本次循环,进行下次循环的功能???
谢谢
...全文
1532 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
songzhenxun 2011-11-09
  • 打赏
  • 举报
回复
使用goto
duqiangcise 2010-03-12
  • 打赏
  • 举报
回复
create or replace procedure test_proc
as
v_number number:=0;
begin
for i in 1..100 loop
begin
select num into v_number from tab_test where id=to_char(i);
exception
when no_data_found then
null;--有异常时,什么也不执行
end;
end loop;
end test_proc;

就向java中也有goto一样,但在实际的开发中又有谁用goto呢?东跳西跳的,最后把自己给跳晕了。
不建议使用goto(个人看法)。
MountLion 2010-03-11
  • 打赏
  • 举报
回复
简单的说,没有。
一般的做法是用goto代替。
tangren 2010-03-10
  • 打赏
  • 举报
回复
oracle 11g已提供continue;
oracle 10g及以下,使用goto来替代,例如

SQL> set serveroutput on;
SQL> declare
2 begin
3 for i in 1..10 loop
4 if mod(i,2)=0 then
5 goto next;
6 end if;
7 dbms_output.put_line(i);
8 <<next>>
9 null;
10 end loop;
11 end;
12 /
1
3
5
7
9

PL/SQL 过程已成功完成。

SQL>


注意:<<next>>标签后的null;语句不可少,因为goto标签后必须紧接着一个执行语句
chogo 2010-03-10
  • 打赏
  • 举报
回复
定义一个异常处理块,并把它放到循环体的最后,在需要continue的时候抛出这个异常。
47522341 2010-03-10
  • 打赏
  • 举报
回复
declare
i integer;
begin
i := 0;
while i < 10 loop
if i = 3 then
-- i := i +1;
goto end_loop;
end if;
dbms_output.put_line(i);

<<end_loop>>
i:= i+1;
end loop;
end;
47522341 2010-03-10
  • 打赏
  • 举报
回复
将剩余的语句包括在一个if 语句中,if的条件设置为你希望continue的条件
vc555 2010-03-10
  • 打赏
  • 举报
回复
引用 2 楼 jane_64 的回复:
exit退出循环,结合其它条件可以达到进行下次循环的功能。

你exit就退出整个loop了。如何再次loop?
Jane_64 2010-03-10
  • 打赏
  • 举报
回复
exit退出循环,结合其它条件可以达到进行下次循环的功能。
vc555 2010-03-10
  • 打赏
  • 举报
回复
可以通过exception方式来终止本次循环,进入下一次循环。
作者:Steven Feuerstein, Bill Pribyl 出版日期:October 1, 2009 出版社:O'Reilly 页数:1226 ISBN:ISBN-10: 0596514468 ISBN-13: 978-0596514464 文件格式:PDF 文件大小:15.06 MB Review If you’re doing database application development in the Oracle environment, you’re going to have to know PL/SQL, the company’s extended query and update language. If you want your programs to exploit the special capabilities of Oracle software, you’ll need to know the language well. That’s where the third edition of Oracle PL/SQL Programming comes into play. It’s an absolutely comprehensive reference (as well as a rather extensive tutorial) on PL/SQL, ideally suited to answering your questions about how to perform some programming tasks and reminding you of the characteristics of functions, triggers, and other elements of the database programmer’s toolkit. The new edition covers calls to Java methods from within PL/SQL programs, autonomous transactions, object type inheritance, and the new Timestamp and XMLType data types. There’s also more information about server internals–the way PL/SQL programs are run–than before, better enabling readers to optimize their code for fast and safe execution. Steven Feuerstein takes care to explain, with prose and example code, the characteristics of PL/SQL elements. In explaining number conversions, for example, he explores Oracle’s different ways of formatting numbers, then details the behavior of the to_number function under different conditions (with and without a specified format model, and with National Language Support information attached). It’s a helpful approach that will have readers using the index to locate places in which Feuerstein mentions language elements of interest. –David Wall Topics covered: How to use Oracle PL/SQL in all its manifestations through Oracle9i. Fundamentals of program structure (loops, cases, exceptions, etc.) and execution get attention, as do data types, transaction management, triggers, and the object-oriented aspects of the language. There’s also coverage of calls to external Java and C programs. –This text refers to the Paperback edition. Product Description This book is the definitive reference on PL/SQL, considered throughout the database community to be the best Oracle programming book available. Like its predecessors, this fifth edition of Oracle PL/SQL Programming covers language fundamentals, advanced coding techniques, and best practices for using Oracle’s powerful procedural language. Thoroughly updated for Oracle Database 11g Release 2, this edition reveals new PL/SQL features and provides extensive code samples, ranging from simple examples to complex and complete applications, in the book and on the companion website. This indispensable reference for both novices and experienced Oracle programmers will help you: Get PL/SQL programs up and running quickly, with clear instructions for executing, tracing, testing, debugging, and managing PL/SQL code Optimize PL/SQL performance with the aid of a brand-new chapter in the fifth edition Explore datatypes, conditional and sequential control statements, loops, exception handling, security features, globalization and localization issues, and the PL/SQL architecture Understand and use new Oracle Database 11g features, including the edition-based redefinition capability, the function result cache, the new CONTINUE statement, fine-grained dependency tracking, sequences in PL/SQL expressions, supertype invocation from subtypes, and enhancements to native compilation, triggers, and dynamic SQL Use new Oracle Database 11g tools and techniques such as PL/Scope, the PL/SQL hierarchical profiler, and the SecureFiles technology for large objects Build modular PL/SQL applications using procedures, functions, triggers, and packages

17,137

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧