I would like to know how I can exit execution when an error occurs. There is a sentence in Microsoft SQL Server RETURNthat does this work. But I would like to know similar functionality in Oracle. I am using Oracle Sql Developer. Here is the script I am using:
The first block throws an error due to a violation of the unique key, although it throws an error, execution proceeds to the next block and executes the insert statement. I want to finish the execution or exit the first block of the code itself. Please help me write the code.
The first anonymous PL / SQL block:
set serveroutput on;
BEGIN
insert into test values(1);
insert into test values(1);
COMMIT;
dbms_output.put_line('PRINT SOMETHING 1');
EXCEPTION
WHEN OTHERS THEN
if sqlcode <> 0
then
dbms_output.put_line(SQLCODE || ' ' || SQLERRM);
RAISE;
end if;
return;
END;
/
Second anonymous PL / SQL block:
set serveroutput on;
BEGIN
insert into test values(6);
COMMIT;
dbms_output.put_line('PRINT SOMETHING');
EXCEPTION
WHEN OTHERS THEN
if sqlcode <> 0
then
dbms_output.put_line(SQLCODE || ' ' || SQLERRM);
RAISE;
end if;
return;
END;
/
source
share