PL/SQL Tutorials - HANDLING ERRORS AND EXCEPTIONS

本文介绍了PLSQL中常见的错误类型及其处理方法,包括ACCESS_INTO_NULL、CASE_NOT_FOUND等内部异常,以及如何使用EXCEPTION_INIT、SQLCODE和SQLERRM等进行错误处理。

PLSQL handles the errors caused at the server level and publishes them using the following functions:

EXCEPTION This datatype is declared in DECLARE section of the PLSQL code enables to call those as and when they are required.

[@more@]

An internal exception is raised implicitly whenever your PL/SQL program violates an Oracle rule or exceeds a system-dependent limit. Every Oracle error has a number, but exceptions must be handled by name. So, PL/SQL predefines some common Oracle errors as exceptions. For example, PL/SQL raises the predefined exception NO_DATA_FOUND if a SELECT INTO statement returns no rows.

To handle other Oracle errors, you can use the OTHERS handler.

The functions SQLCODE and SQLERRM are especially useful in the OTHERS handler because they return the Oracle error code and message text. Alternatively, you can use the pragma EXCEPTION_INIT to associate exception names with Oracle error codes.

Exception: ACCESS_INTO_NULL
Oracle Error: ORA-06530
SQLCODE: -6530

Your program attempts to assign values to the attributes of an uninitialized (atomically null) object.

Exception: CASE_NOT_FOUND
Oracle Error: ORA-06592
SQLCODE: -6592

None of the choices in the WHEN clauses of a CASE statement is selected, and there is no ELSE clause.

Exception: COLLECTION_IS_NULL
Oracle Error: ORA-06531
SQLCODE: -6531

Your program attempts to apply collection methods other than EXISTS to an uninitialized (atomically null) nested table or varray, or the program attempts to assign values to the elements of an uninitialized nested table or varray.

Exception: CURSOR_ALREADY_OPEN
Oracle Error: ORA-06511
SQLCODE: -6511

Your program attempts to open an already open cursor. A cursor must be closed before it can be reopened. A cursor FOR loop automatically opens the cursor to which it refers. So, your program cannot open that cursor inside the loop.

Exception: DUP_VAL_ON_INDEX
Oracle Error: ORA-00001
SQLCODE: -1

Your program attempts to store duplicate values in a database column that is constrained by a unique index.

Exception: INVALID_CURSOR
Oracle Error: ORA-01001
SQLCODE: -1001

Your program attempts an illegal cursor operation such as closing an unopened cursor.

Exception: INVALID_NUMBER
Oracle Error: ORA-01722
SQLCODE: -1722

In a SQL statement, the conversion of a character string into a number fails because the string does not represent a valid number. (In procedural statements, VALUE_ERROR is raised.) This exception is also raised when the LIMIT-clause expression in a bulk FETCH statement does not evaluate to a positive number.

Exception: LOGIN_DENIED
Oracle Error: ORA-01017
SQLCODE: -1017

Your program attempts to log on to Oracle with an invalid username and/or password.

Exception: NO_DATA_FOUND
Oracle Error: ORA-01403
SQLCODE: +100

A SELECT INTO statement returns no rows, or your program references a deleted element in a nested table or an un-initialized element in an index-by table. SQL aggregate functions such as AVG and SUM always return a value or a null. So, a SELECT INTO statement that calls an aggregate function never raises NO_DATA_FOUND. The FETCH statement is expected to return no rows eventually, so when that happens, no exception is raised.

Exception: NOT_LOGGED_ON
Oracle Error: ORA-01012
SQLCODE: -1012

Your program issues a database call without being connected to Oracle.

Exception: PROGRAM_ERROR
Oracle Error: ORA-06501
SQLCODE: -6501

PL/SQL has an internal problem.

Exception: ROWTYPE_MISMATCH
Oracle Error: ORA-06504
SQLCODE: -6504

The host cursor variable and PL/SQL cursor variable involved in an assignment have incompatible return types. For example, when an open host cursor variable is passed to a stored subprogram, the return types of the actual and formal parameters must be compatible.

Exception: SELF_IS_NULL
Oracle Error: ORA-30625
SQLCODE: -30625

Your program attempts to call a MEMBER method on a null instance. That is, the built-in parameter SELF (which is always the first parameter passed to a MEMBER method) is null.

Exception: STORAGE_ERROR
Oracle Error: ORA-06500
SQLCODE: -6500

PL/SQL runs out of memory or memory has been corrupted.

Exception: SUBSCRIPT_BEYOND_COUNT
Oracle Error: ORA-06533
SQLCODE: -6533

Your program references a nested table or varray element using an index number larger than the number of elements in the collection.

Exception: SUBSCRIPT_OUTSIDE_LIMIT
Oracle Error: ORA-06532
SQLCODE: -6532

Your program references a nested table or varray element using an index number (-1 for example) that is outside the legal range.

Exception: SYS_INVALID_ROWID
Oracle Error: ORA-01410
SQLCODE: -1410

The conversion of a character string into a universal rowid fails because the character string does not represent a valid rowid.

Exception: TIMEOUT_ON_RESOURCE
Oracle Error: ORA-00051
SQLCODE: -51

A time-out occurs while Oracle is waiting for a resource.

Exception: TOO_MANY_ROWS
Oracle Error: ORA-01422
SQLCODE: -1422

A SELECT INTO statement returns more than one row.

Exception: VALUE_ERROR
Oracle Error: ORA-06502
SQLCODE: -6502

An arithmetic, conversion, truncation, or size-constraint error occurs. For example, when your program selects a column value into a character variable, if the value is longer than the declared length of the variable, PL/SQL aborts the assignment and raises VALUE_ERROR. In procedural statements, VALUE_ERROR is raised if the conversion of a character string into a number fails. (In SQL statements, INVALID_NUMBER is raised.)

Exception: ZERO_DIVIDE
Oracle Error: ORA-01476
SQLCODE: -1476

Your program attempts to divide a number by zero.

An Example of handling exception (from Oracle Docs)

DECLARE
past_due EXCEPTION;
acct_num NUMBER;
BEGIN
DECLARE ---------- sub-block begins
past_due EXCEPTION; -- this declaration prevails
acct_num NUMBER;
BEGIN
...
IF ... THEN
RAISE past_due; -- this is not handled
END IF;
END; ------------- sub-block ends
EXCEPTION
WHEN past_due THEN -- does not handle RAISE exception
...
END;

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/9896745/viewspace-933533/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/9896745/viewspace-933533/

(Kriging_NSGA2)克里金模型结合多目标遗传算法求最优因变量及对应的最佳自变量组合研究(Matlab代码实现)内容概要:本文介绍了克里金模型(Kriging)与多目标遗传算法NSGA-II相结合的方法,用于求解最优因变量及其对应的最佳自变量组合,并提供了完整的Matlab代码实现。该方法首先利用克里金模型构建高精度的代理模型,逼近复杂的非线性系统响应,减少计算成本;随后结合NSGA-II算法进行多目标优化,搜索帕累托前沿解集,从而获得多个最优折衷方案。文中详细阐述了代理模型构建、算法集成流程及参数设置,适用于工程设计、参数反演等复杂优化问题。此外,文档还展示了该方法在SCI一区论文中的复现应用,体现了其科学性与实用性。; 适合人群:具备一定Matlab编程基础,熟悉优化算法和数值建模的研究生、科研人员及工程技术人员,尤其适合从事仿真优化、实验设计、代理模型研究的相关领域工作者。; 使用场景及目标:①解决高计算成本的多目标优化问题,通过代理模型降低仿真次数;②在无法解析求导或函数高度非线性的情况下寻找最优变量组合;③复现SCI高水平论文中的优化方法,提升科研可信度与效率;④应用于工程设计、能源系统调度、智能制造等需参数优化的实际场景。; 阅读建议:建议读者结合提供的Matlab代码逐段理解算法实现过程,重点关注克里金模型的构建步骤与NSGA-II的集成方式,建议自行调整测试函数或实际案例验证算法性能,并配合YALMIP等工具包扩展优化求解能力。
/etc /etc/systemd /etc/systemd/system /etc/systemd/system/haply-inverse-service.service /usr /usr/bin /usr/bin/00-haply-inverse-device-list /usr/bin/01-haply-inverse-print-inverse3 /usr/bin/02-haply-inverse-print-verse-grip /usr/bin/03-haply-inverse-print-wireless-verse-grip /usr/bin/04-haply-inverse-hello-floor /usr/bin/haply-inverse-service /usr/share /usr/share/doc /usr/share/doc/haply-inverse-service /usr/share/doc/haply-inverse-service/README /usr/share/doc/haply-inverse-service/copyright /usr/share/doc/haply-inverse-service/examples /usr/share/doc/haply-inverse-service/examples/tutorials /usr/share/doc/haply-inverse-service/examples/tutorials/00-haply-inverse-device-list /usr/share/doc/haply-inverse-service/examples/tutorials/00-haply-inverse-device-list/00-haply-inverse-device-list.cpp /usr/share/doc/haply-inverse-service/examples/tutorials/00-haply-inverse-device-list/CMakeLists.txt /usr/share/doc/haply-inverse-service/examples/tutorials/00-haply-inverse-device-list/README.md /usr/share/doc/haply-inverse-service/examples/tutorials/01-haply-inverse-print-inverse3 /usr/share/doc/haply-inverse-service/examples/tutorials/01-haply-inverse-print-inverse3/01-haply-inverse-print-inverse3.cpp /usr/share/doc/haply-inverse-service/examples/tutorials/01-haply-inverse-print-inverse3/CMakeLists.txt /usr/share/doc/haply-inverse-service/examples/tutorials/01-haply-inverse-print-inverse3/README.md /usr/share/doc/haply-inverse-service/examples/tutorials/02-haply-inverse-print-verse-grip /usr/share/doc/haply-inverse-service/examples/tutorials/02-haply-inverse-print-verse-grip/02-haply-inverse-print-verse-grip.cpp /usr/share/doc/haply-inverse-service/examples/tutorials/02-haply-inverse-print-verse-grip/CMakeLists.txt /usr/share/doc/haply-inverse-service/examples/tutorials/02-haply-inverse-print-verse-grip/README.md /usr/share/doc/haply-inverse-service/examples/tutorials/03-haply-inverse-print-wireless-verse-grip /usr/share/doc/haply-inverse-service/examples/tutorials/03-haply-inverse-print-wireless-verse-grip/03-haply-inverse-print-wireless-verse-grip.cpp /usr/share/doc/haply-inverse-service/examples/tutorials/03-haply-inverse-print-wireless-verse-grip/CMakeLists.txt /usr/share/doc/haply-inverse-service/examples/tutorials/03-haply-inverse-print-wireless-verse-grip/README.md /usr/share/doc/haply-inverse-service/examples/tutorials/04-haply-inverse-hello-floor /usr/share/doc/haply-inverse-service/examples/tutorials/04-haply-inverse-hello-floor/04-haply-inverse-hello-floor.cpp /usr/share/doc/haply-inverse-service/examples/tutorials/04-haply-inverse-hello-floor/CMakeLists.txt /usr/share/doc/haply-inverse-service/examples/tutorials/04-haply-inverse-hello-floor/README.md /usr/share/doc/haply-inverse-service/examples/tutorials/CMakeLists.txt /usr/share/doc/haply-inverse-service/examples/tutorials/CMakeSettings.json /usr/share/doc/haply-inverse-service/examples/tutorials/README.md /usr/share/doc/haply-inverse-service/examples/tutorials/external /usr/share/doc/haply-inverse-service/examples/tutorials/external/CMakeLists.txt /usr/share/doc/haply-inverse-service/examples/tutorials/external/json /usr/share/doc/haply-inverse-service/examples/tutorials/external/json/CMakeLists.txt /usr/share/doc/haply-inverse-service/examples/tutorials/external/json/LICENSE /usr/share/doc/haply-inverse-service/examples/tutorials/external/json/README.md /usr/share/doc/haply-inverse-service/examples/tutorials/external/libhv /usr/share/doc/haply-inverse-service/examples/tutorials/external/libhv.h /usr/share/doc/haply-inverse-service/examples/tutorials/external/libhv/CMakeLists.txt /usr/share/doc/haply-inverse-service/examples/tutorials/external/libhv/LICENSE /usr/share/doc/haply-inverse-service/examples/tutorials/external/libhv/README.md /usr/share/haply-inverse-service /usr/share/haply-inverse-service/assets /usr/share/haply-inverse-service/assets/audio /usr/share/haply-inverse-service/assets/audio/notification_test.wav /usr/share/haply-inverse-service/assets/dashboard /usr/share/haply-inverse-service/assets/dashboard/haply.png /usr/share/haply-inverse-service/assets/dashboard/index.html /usr/share/haply-inverse-service/assets/dashboard/style.css /usr/share/haply-inverse-service/assets/icons /usr/share/haply-inverse-service/assets/icons/haply.ico /usr/share/haply-inverse-service/assets/icons/haply.png /usr/share/haply-inverse-service/assets/icons/haply_on.ico /usr/share/haply-inverse-service/assets/icons/haply_on.png /usr/share/haply-inverse-service/assets/icons/haply_on_.ico
07-27
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值