Oracle
  Home arrow Oracle arrow Page 3 - Database Interaction with PL/SQL, part 2
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
ORACLE

Database Interaction with PL/SQL, part 2
By: Jagadish Chatarji
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 18
    2005-05-31


    Table of Contents:
  • Database Interaction with PL/SQL, part 2
  • UPDATE with RETURNING clause
  • TYPE with RECORD declaration
  • Accessing more than one row in PL/SQL (TYPE with TABLE)

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Database Interaction with PL/SQL, part 2 - TYPE with RECORD declaration
    ( Page 3 of 4 )

    Until now, we have been working either with %TYPE or %ROWTYPE. This means we are working with either one value or one complete record. How do we create our own data type, with our own specified number of values to hold? This is where TYPE and RECORD come in. Those who are familiar with the C language can consider this to be a structure declaration. Let me explain this to you in detail.

    Let us consider a table of about 20 columns.  I always need to work with only seven of those columns. If I use %ROWTYPE, I get all 20 values unnecessarily. At the same time, my program will be bit clumsy if I use seven %TYPE declarations. A better way to solve this solution is by defining my own data type, which can hold seven values. Then I declare the variables of my new data type and work with them. The following example illustrates this.

    declare

    TYPE t_emprec IS RECORD

    (

    name emp.ename%type,

    salary emp.sal%type,

    job emp.job%type

    );

    v_emp t_emprec;

    v_empno emp.empno%type := &empno;

    begin

    select ename,sal,job into v_emp

    from emp where empno = v_empno;

    dbms_output.put_line ('Name : ' || v_emp.name);

    dbms_output.put_line ('Salary : ' || v_emp.salary);

    dbms_output.put_line ('Job : ' || v_emp.job);

    end;

    Let us examine the above program part by part. First, consider the following:

    TYPE t_emprec IS RECORD

    (

    name emp.ename%type,

    salary emp.sal%type,

    job emp.job%type

    );

    The above defines a new data type named "t_emprec" (just like %ROWTYPE with limited specified fields) which can hold three fields, namely "name," "salary" and "job."

    v_emp t_emprec;

    The above statement declares a variable "v_emp" based on the datatype "t_emprec." This means that "v_emp" internally contains the fields "name," "salary" and "job."

    select ename,sal,job into v_emp

    from emp where empno = v_empno;

    The above statement places the values of "ename," "sal" and "job" into fields "name," "salary" and "job" of the variable "v_emp" respectively.

    dbms_output.put_line ('Name : ' || v_emp.name);

    dbms_output.put_line ('Salary : ' || v_emp.salary);

    dbms_output.put_line ('Job : ' || v_emp.job);

    And the above displays all the values available fields of the variable "v_emp."



     
     
    >>> More Oracle Articles          >>> More By Jagadish Chatarji
     

       

    ORACLE ARTICLES

    - Oracle's Turn to Play in the Sun
    - Implementing and Using Oracle`s Restore Poin...
    - Tuning PL/SQL Code
    - Debugging PL/SQL Code
    - Testing PL/SQL Code
    - Working With PL/SQL Code
    - Conditional Compilation for Oracle Database ...
    - Compile-Time Warnings for Oracle DB 10g
    - Compiling PL/SQL Code for an Oracle Database
    - Troubleshooting PL/SQL Code
    - Managing PL/SQL Code
    - Data Manipulation and More for HTML DB Appli...
    - Oracle Database Fundamentals
    - Adding Processes to HTML DB Applications
    - Adding Computations, Processes, and Validati...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek