Posted By

mprabhuram on 08/30/10


Oracle PLSQL

Versions (?)

Who likes this?

1 person have marked this snippet as a favorite


Variable Declaration Using Database Objects %rowtype

 / Published in: SQL


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

  1. -- 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.
  3. v_auth_name author.author_last_name%type;
  6. -- You can also create records using the %rowtype declaration.
  8. r_auth author%rowtype;

Report this snippet  

You need to login to post a comment.