Hard to Get

--人生在世 难得二字

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 :: 管理 ::

PL/SQL Best Practices [7][Data Structures]-Data Types & Structures

Leverage PL/SQL Datatypes
PL/SQL offers a real Boolean datatype, unlike the Oracle database.
    *. Values are TRUE, FALSE, NULL. These are not string values.
    *. You can also build Boolean functions and create Boolean arguments in parameter lists.

BINARY_INTEGER are represented as signed binary numbers, the internal format for PL/SQL.
    *. Can be used in calculations without conversion, so they are (at least theoretically) more efficient
Note:  BINARY_INTEGERS are a function of PL/SQL Version 2.2 and are not available in earlier versions of PL/SQL. When using these datatypes in stored procedures and functions it is important to note that client side PL/SQL (in Forms4.5, for example) will not be able to use any procedures which have BINARY_INTEGER parameters or functions which return BINARY_INTEGERs.
A good example of how this can affect you is the DBMS_UTILITY package and the GET_TIME function which returns BINARY_INTEGER. When used in Forms 4.5 from a 2.2 database, you must create a wrapper package which returns NUMBER instead of BINARY_INTEGER.

Composite data structures (records and PL/SQL tables) can greatly improve code readability, maintainability and performance.

Streamline Code with PL/SQL Records
Create a record from:

    *. Database table using %ROWTYPE
    *. Cursor using %ROWTYPE
    *. Your own design using the record TYPE statement.
Use object-oriented design principles.
    *. Collect together -- and manipulate -- the individual attributes of an entity as an object.
Reduce code volume.
    *. Perform record-level operations, such as an aggregate assignment.
    *. Clean up procedural interfaces by replacing multiple individual parameters with a single record parameter.
Improve code quality.
    *. Fewer opportunities for mistakes in coding.
    *. Changes to individual attributes in record will not affect record-level, aggregate operations.
Use Records in Top-Down Design
Minimize typing and defer addressing details, such as the particular fields needed to perform computations.

 1FOR ord_rec IN ord_cur
 2LOOP
 3   get_line_item_data (ord_rec, li_rec);
 4   insert_lineitem 
 5      (li_rec, c_total_profit);
 6   insert_lineitem (li_rec, c_net_sales);
 7   IF order_exceeds_maximum (ord_rec)
 8   THEN
 9      create_override (ord_rec, li_rec);
10   END IF;
11END LOOP;
12

Leverage PL/SQL Tables
Use PL/SQL tables to create traditional data structures:
    *. Lists, Stacks, Arrays
Take advantage of a PL/SQL table's interesting characteristics:
    *. A one-dimensional, unbounded, sparse collection of homogenous elements, indexed by integers.
    *. More to the point: the row number can be an intelligent key:

      company_names (v_newcomp_id) := 'FEUERSTEIN INC.';
posted on 2005-09-12 22:19  Del  阅读(153)  评论(0)    收藏  举报