Oracle
  Home arrow Oracle arrow Page 4 - Database Interaction with PL/SQL: OBJE...
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
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? 
ORACLE

Database Interaction with PL/SQL: OBJECT and OBJECT
By: Jagadish Chatarji
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 20
    2005-06-14

    Table of Contents:
  • Database Interaction with PL/SQL: OBJECT and OBJECT
  • Accessing OBJECT TYPE using PL/SQL
  • Working with column based OBJECTs
  • Accessing column based OBJECTs in PL/SQL

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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: OBJECT and OBJECT - Accessing column based OBJECTs in PL/SQL


    (Page 4 of 4 )

    We will use the same concept in previous section, but with PL/SQL.  Let us consider the following code.

    declare
        v_OffAddress   t_Address;
        v_ename        varchar2(20) := 'jag';
    begin
        select OffAddress into v_OffAddress
        from employees where ename = v_ename;
        dbms_output.put_line(v_OffAddress.city);
    end;
    /

    I hope the above program looks very much familiar to that of PL/SQL RECORD fetching.  In this case, VALUE is not necessary as, we are not converting the whole row as OBJECT.  Let us consider another example:

    declare
        TYPE tbl_Address is TABLE of t_Address index by pls_integer;
        v_tblAddress    tbl_Address;
        v_ename                       varchar2(20) := 'jag';
    begin
        select OffAddress, ResAddress into v_tblAddress(0), v_tblAddress(1)
        from employees where ename = v_ename;
        dbms_output.put_line(v_tblAddress(0).city);
        dbms_output.put_line(v_tblAddress(1).city);
    end;
    /

    The above program introduces several new concepts (even though it looks almost the same as previous examples).  Let me explain part by part.

    TYPE tbl_Address is TABLE of t_Address index by pls_integer;

    Till now, I never explained the part ‘index by…’.  According to the above statement, I am creating a new data type ‘tbl_address’ which can hold any number of records (just in the form of a table) based on the OBJECT TYPE ‘t_Address’.  The extension ‘index by pls_integer’ creates an index based table.  This means the PL/SQL table gets indexed based on the records populated.  The ‘pls_integer’ can also be replaced using ‘binary_integer’.  Now each and every row within the table are accessible using an index (or counter).

    v_tblAddress    tbl_Address;

    I hope you can understand this.  We are just creating a variable ‘v_tblAddress’ based on the PL/SQL TABLE type ‘tbl_Address’. 

    select OffAddress, ResAddress into v_tblAddress(0), v_tblAddress(1)
    from employees where ename = v_ename;

    The above SELECT statement retrieves the objects available in the two columns (OffAddress and ResAddress) and places them within ‘v_tblAddress’ at two different locations i.e., 0 and 1.

    dbms_output.put_line(v_tblAddress(0).city);
    dbms_output.put_line(v_tblAddress(1).city);

    Finally, we display the cities of both addresses as shown above.

    It is not exactly necessary to follow the same method as above.  But this way I can introduce the index based PL/SQL tables along with OBJECTs together.  If necessary we can also use BULK COLLECT to retrieve more than one row.  I leave this to you, the readers, as an exercise.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · Hello guys, this is my article on working with OBJECT and OBJECT TYPE in PL/SQL. You...
     

       

    ORACLE ARTICLES

    - 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...
    - Sub-templates and More with Oracle HTML DB





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
    Stay green...Green IT