简体   繁体   English

Oracle中@@ Error的等效项是什么

[英]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. 我在SQL Server中有以上代码。我找不到与@@ Error对应的oracle。

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). 我同意@Kfinity提供的异常处理程序来捕获SQL语句(或与此有关的PL / SQL语句)引发的错误。

It might also be helpful to know that the direct correlation of @@Error in PL/SQL is SQLCODE. 知道PL / SQL中@@ Error的直接关联是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! 如果为0,那么.....没有错误!

It sounds like you're trying to do error handling. 听起来您正在尝试进行错误处理。 In PL/SQL it usually looks like this: 在PL / SQL中,通常如下所示:

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. 您可以对当前正在使用的整个PL / SQL块(函数,过程等)执行此操作,也可以将单个语句包装在带有异常处理程序的匿名PL / SQL块中,如果您需要更多TRY..CATCH功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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