[英]How do i continue running my program after encountering exception in SQL?
我已編寫PL / SQL代碼以僅打印大於id = 4的記錄。 我在程序中使用了goto語句,沒有異常檢測到。 遇到異常后,請幫助我繼續執行該程序。 我的代碼是
declare
cursor cur is select * from student;
c student%rowtype;
lt3 exception;
PRAGMA
exception_init(lt3,-77);
begin
open cur;
loop
<<backup>>
fetch cur into c;
if c.id < 4 then
raise lt3;
else
dbms_output.put_line(c.name);
end if;
end loop;
close cur;
exception
when lt3 then
dbms_output.put_line('Exception encountered');
goto backup;
end;
/
我應該在哪里改變?
我在錯誤
ERROR at line 24:
ORA-06550: line 24, column 7:
PLS-00201: identifier 'BACKUP' must be declared
ORA-06550: line 24, column 2:
PL/SQL: Statement ignored
如果可以,應該避免在任何代碼中使用goto語句。
下面的代碼應該可以實現您想做的事情。 我沒有數據庫訪問權限,所以可能語法不正確。
declare
cursor cur is select * from student;
c student%rowtype;
lt3 exception;
PRAGMA
exception_init(lt3,-77);
begin
open cur;
loop
begin
fetch cur into c;
if c.id < 4 then
raise lt3;
else
dbms_output.put_line(c.name);
end if;
exception
when lt3 then
dbms_output.put_line('Exception encountered');
end;
end loop;
close cur;
exception
when others then
dbms_output.put_line('other error encountered');
end;
您確實應該選擇id> 4以避免異常。
后藤將無法以這種方式工作。 您需要使用continue或break來執行控制。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.