Tài liệu PL/SQL User’s Guide and Reference phần 5

Thảo luận trong 'Căn Bản' bắt đầu bởi Thúy Viết Bài, 5/12/13.

  1. Thúy Viết Bài

    Thành viên vàng

    Bài viết:
    198,891
    Được thích:
    167
    Điểm thành tích:
    0
    Xu:
    0Xu
    User-Defined Exceptions
    PL/SQL lets you define exceptions of your own. Unlike predefined exceptions,
    user-defined exceptions must be declared and must be raised explicitly by RAISE
    statements.
    Declaring Exceptions
    Exceptions can be declared only in the declarative part of a PL/SQL block,
    subprogram, or package. You declare an exception by introducing its name,
    followed by the keyword EXCEPTION. In the following example, you declare an
    exception named past_due:
    DECLARE
    past_due EXCEPTION;
    Exception and variable declarations are similar. But remember, an exception is an
    error condition, not a data item. Unlike variables, exceptions cannot appear in
    assignment statements or SQL statements. However, the same scope rules apply to
    variables and exceptions.
    Scope Rules
    You cannot declare an exception twice in the same block. You can, however, declare
    the same exception in two different blocks.
    Exceptions declared in a block are considered local to that block and global to all its
    sub-blocks. Because a block can reference only local or global exceptions, enclosing
    blocks cannot reference exceptions declared in a sub-block.
    If you redeclare a global exception in a sub-block, the local declaration prevails. So,
    the sub-block cannot reference the global exception unless it was declared in a
    labeled block, in which case the following syntax is valid:
    block_label.exception_name
     

    Các file đính kèm:

Đang tải...