简体   繁体   中英

What is the equivalent for @@Error in Oracle

IF @@ERROR <> 0 GOTO ProcError

I have the above code in SQL Server.I am unable to find an oracle equivalent for @@Error.

How can this be achieved?

I agree with @Kfinity's offering of an exception handler to trap an error raised by a SQL statement (or PL/SQL statement for that matter).

It might also be helpful to know that the direct correlation of @@Error in PL/SQL is SQLCODE. If non-zero (which it only is when invoked from within an exception handler) it gives you the error code. If 0, well, then....no error!

It sounds like you're trying to do error handling. In PL/SQL it usually looks like this:

BEGIN
  ...do something...
EXCEPTION WHEN NO_DATA_FOUND THEN -- check for a specific exception
  DBMS_OUTPUT.put_line('No data found exception caught');
WHEN OTHERS THEN -- catch any exception
  DBMS_OUTPUT.put_line('Unexpected error');
  DBMS_OUTPUT.put_line (DBMS_UTILITY.format_error_backtrace); 
  RAISE; -- re-raise the exception after logging it
END;

You can either do this for your entire PL/SQL block that you're currently working with (function, procedure, etc), or you can wrap a single statement in an anonymous PL/SQL block with an exception handler if you want more of a TRY..CATCH functionality.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM