Home > Blockchain >  Oracle - how to stop script execution after any error?
Oracle - how to stop script execution after any error?

Time:05-05

For example, let's say we have the following script to execute in prod.

drop index idx_test1;

drop index idx_test2;

But, after execute first instruction we get the error: ORA-00054: resource busy and acquire with NOWAIT specified or timeout expired. From here I'd like to stop all subsequent instructions. Is there any way to do it in sqlplus and sqldeveloper/PL/SQL Developer?

CodePudding user response:

I would recommend running scripts using Sql*Plus. You would use

WHENEVER SQLERROR EXIT SQL.SQLCODE ROLLBACK 

This can be part of your glogin.sql or just as a header of your production script.

This will also send the error code to the calling process for your own logging so if you have some orchestrator, it can know what's happened.

  • Related