Oracle Database Programming

Embed Size (px)

Citation preview

  • 8/8/2019 Oracle Database Programming

    1/24

    ***************************************************************************************DML := (Data Manipulation Language).A Slash (/) sign at the end of the code indicates the termination of the code.***************************************************************************************Partition Applications

    (The process of separating code and placing individual program units ona server or client)

    You can store program units on the server or the clients depending on you needs.(A program unit stored on an Oracle server is accessible to all the appl

    ications on client nodes).(When the program unit is stored on a client node, the unit can referenc

    e program units on the same client node as well as program unit on the server).

    A program unit is stored on the server when:

    -The code is SQL-intensive and contains a large number of DML and SELECT stateme

    nts. (Typically you store database triggers on the server).(Can be a procedure, a function, a package, or a database trigger).

    -The program unit does not need to reference Developer applications objects or built-in subprograms.

    -The program unit is needed by many applications on the server and client nodes.

    -You need to implement system-wide rules.(Such as database trigger on the Oracle server).

    -The program unit needs to use features not available in Oracle application tool

    s.

    When you store a program unit on the server:

    -The program unit is processed by the PL/SQL engine within the Oracle server.

    -Client/server traffic is reduced.(Program units stored on the client are transfered to the server for par

    sing and execution, this resutls in client/server traffic, to reduce that traffic place program units on the server).

    -The program unit can only reference server-side objects.

    (Client-side objects are inaccessible to the program units stored on thedatabase server).

    -Users must have the EXECUTE privilege on the program unit, unless the user is the owner.

    (When a user is not the owner of a program unit, the user needs the EXECUTE privilege to access and use the program unit sotred on the database server).

    A program unit stored on a client-side:

    -Needs a database connection only if SQL calls or server-side call are made.

    -Can reference server-side and Developer objects.

    (Server-side objects such as tables, views, sequences, and packages).(Developer objects such as form variables and form built-in packages).

  • 8/8/2019 Oracle Database Programming

    2/24

    -Sends SQL statements for parsing and execution.

    -Is processed by the PL/SQL engine in the client application.(The Oracle Developer Forms and Procedure Builder are examples of client

    applications processes).

    -Can call both server-side and other client-side program units.

    (This includes Developer built-in programs stored on the same client node)._______________________________________________________________________Exceptions

    1.-Predefined Oracle server exceptions.2.-Non-predefined Oracle server exceptions.3.-User-defined exceptons.

    Predefined exceptions examples:

    -NO_DATA_FOUND

    -TOO_MANY_ROWS-INVALID_CURSOR-ZERO_DIVIDE-DUP_VAL_ON_INDEX

    Non-Predefined exceptions features:

    -Unnamed Oracle server exceptions.-20000 exceptions.-Server raises the exception implicitly.

    Trapping Non-predefined Oracle server exceptions:

    DECLARE EXCEPTION;PRAGMA_EXCEPTION_INIT (,);--Any further declarations

    BEGIN--Statements

    EXCEPTIONSWHEN THEN-Statements for handler

    END;

    Example use of a User-Defined Exception

    DECLARE EXCEPTION;--Any further declarations

    BEGIN--StatementsIF SQL%NOTFOUND THEN

    RAISE ;END IF;--Statements

    EXCEPTIONSWHEN THEN--Statements for handler

    END;__________________________________________________________________Trapping Exceptions

  • 8/8/2019 Oracle Database Programming

    3/24

    -Exception handled by current block

    -Exception handled by enclosing blocks

    -Exception propagates to calling environment

    The oracle server error number must be between -20000 and -20999, together witha user-specified error message.__________________________________________________________________

    ___________/-Procedures//-Functions//-Cursors

    Stored Package