您的位置:首页 > 数据库

What does the SQLCODE Function do

2012-02-25 15:17 337 查看

What does the SQLCODE Function do?

The SQLCODE function returns the error number associated with the most recently raised error exception. This function should only be used within the Exception Handling section of your code:

EXCEPTION

    WHEN exception_name1 THEN

        [statements]

    WHEN exception_name2 THEN

        [statements]

    WHEN exception_name_n THEN

        [statements]

    WHEN OTHERS THEN

        [statements]

END [procedure_name];

You could use the SQLCODE function to raise an error as follows:

EXCEPTION

   WHEN OTHERS THEN

      raise_application_error(-20001,'An error was encountered - '||SQLCODE||' -ERROR- '||SQLERRM);

END;

Or you could log the error to a table as follows:

EXCEPTION

   WHEN OTHERS THEN

      err_code := SQLCODE;

      err_msg := substr(SQLERRM, 1, 200);

      INSERT INTO audit_table (error_number, error_message)

      VALUES (err_code, err_msg);

END;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息