{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}


DECLARING VARIABLES - database columns You can reference a...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
DECLARING VARIABLES You can declare variables and constants in the declarative part of any PL/SQL block, subprogram, or package birthdate DATE; emp_count SMALLINT := 0; acct_id VARCHAR2 (5) NOT NULL := 'AP001'; credit_limit CONSTANT REAL := 5000.00; If you prefer, you can use the reserved word DEFAULT instead of the assignment operator to initialize variables and constants tax_year SMALLINT DEFAULT 92; valid BOOLEAN DEFAULT FALSE; Using %TYPE. The %TYPE attribute provides the datatype of a variable, constant, or database column. Variables and constants declared using %TYPE are treated like those declared using a datatype name. For example in the declaration below, PL/SQL treats debit like a REAL(7,2) variable. credit REAL(7,2); debit credit%TYPE; The %TYPE attribute is particularly useful when declaring variables that refer to
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: database columns. You can reference a table and column, or you can reference an owner, table, and column. my_dname scott.dept.dname%TYPE; Using %TYPE to declare my_dname has two advantages. First, you need not know the exact datatype of dname. Second, if the database definition of dname changes, the datatype of my_dname changes accordingly at run time. Using %ROWTYPE. The %ROWTYPE attribute provides a record type that represents a row in a table (or view). The record can store an entire row of data selected from the table or fetched by a cursor. emprec emp%rowtype; to access a field from the above variable use the dot notation emprec.ename,emprec.sal etc. ....
View Full Document

{[ snackBarMessage ]}