Hard to Get

--人生在世 难得二字

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

PL/SQL Best Practices [9][Data Structures]-Anchored Declarations

Anchor Declarations with %TYPE and %ROWTYPE
You must declare all variables and constants before you can use them. The best way to declare them is to use %TYPE and %ROWTYPE attributes to anchor your variable to an existing variable or database element. This way you avoid yet another kind of “hard-coding” in your programs.
Hard-Coded Declarations:

ename VARCHAR2(60);
total_sales 
NUMBER (10,2);

Anchored Declarations:

ename emp.ename%TYPE;
total_sales sales_amt
%TYPE;

Benefits of Anchoring
Synchronize PL/SQL variables with database columns and rows.
    * If a variable or parameter does represent database information in your program, always use %TYPE or %ROWTYPE.
    * Keeps your programs in synch with database structures without having to make code changes.
Normalize/consolidate declarations of derived variables throughout your programs.
    * Make sure that all declarations of dollar amounts or entity names are consistent.
    * Change one declaration and upgrade all others with recompilation.

posted on 2005-09-12 22:37  Del  阅读(138)  评论(0)    收藏  举报