Return to Snippet

Revision: 31118
at August 30, 2010 10:29 by mprabhuram


Initial Code
-- Oracle has provided a method to declare a variable using the database object the data is based on.  To execute this use the %type declaration.

v_auth_name author.author_last_name%type;


-- You can also create records using the %rowtype  declaration.

r_auth  author%rowtype;

Initial URL
http://www.rampant-books.com/t_easyoracle_pl_sql_variable_declaration_db_objects.htm

Initial Description
In the examples so far we have declared variables as a separate object using one of PL/SQL’s standard datatypes. Normally a PL/SQL variable is closely tied to a database object and uses the same datatype.  For example, if the variable will hold the book title from the book table , the variable definition must be of the exact same type and size as the table column.  But what happens when the DBA changes the book table so that book_title is defined as a varchar2(60) instead of a varchar2(40)?  It’s important to program in such a way that when the tables are changed, the PL/SQL code does not always need to be changed

Initial Title
Variable Declaration Using Database Objects %rowtype

Initial Tags
Oracle

Initial Language
SQL