Variable Declaration Using Database Objects %rowtype


/ Published in: SQL
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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.
  2.  
  3. v_auth_name author.author_last_name%TYPE;
  4.  
  5.  
  6. -- You can also create records using the %rowtype declaration.
  7.  
  8. r_auth author%rowtype;

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.