Oracle
  Home arrow Oracle arrow Page 3 - 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 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Actuate Whitepapers 
VeriSign Whitepapers 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
IBM developerWorks
 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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Database Interaction with PL/SQL: OBJECT and OBJECT - Working with column based OBJECTs


    (Page 3 of 4 )

    In the previous two sections, we were actually working with rows of OBJECTs within a table.  This means that every row within the table is considered an OBJECT (not individual values within columns).  But they appear as if they directly got stored in the form of column values.  That is the beauty of OBJECT based tables!

    In this section, we will store OBJECTs in columns (rather than in the form of rows).  Let us prepare our scripts accordingly.  Consider the following:

    CREATE or REPLACE TYPE t_Address AS OBJECT
    (
        street    varchar2(20),
        city      varchar2(20),
        state     varchar2(20),
        country   varchar2(20)
    );
    /

    The above script creates an OBJECT type named ‘t_Address’ with fields called street, city, state and country.

    create table employees
    (
        ename           varchar2(20),
        OffAddress      t_Address,
        ResAddress      t_Address
    );

    The above script creates new table employees (make sure you delete the old one) with three columns namely ename, OffAddress and ResAddress.  The most important are the last two columns which are based on the OBJECT TYPE t_Address.  This means each of the two columns can have their own grouped information of street, city, state and country without having any relation between them.  They will be treated as two different unrelated columns of information which will never shared data.  But they got derived from the same OBJECT TYPE.  You can issue the following type of INSERT statements for the table created above.

    insert into employees
    values
    (
        'jag',
        t_address('street 1','Kangar','Perlis','Malaysia'),
        t_address('street 2','BVRM','Andhra Pradesh','India')
    );

    Instead of just simply giving ‘SELECT * FROM employees’, I suggest you to issue in the following manner:

    select e.ename, e.OffAddress.city, e.ResAddress.city from employees e

    Observe the beauty of table alias together with column name and finally the member within the column (city).  In that way you can access any member of object with the respective column name together with alias.  In the same manner, you can also practice other DML commands with the same table.

    More Oracle Articles
    More By Jagadish Chatarji


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

       

    ORACLE ARTICLES

    - 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
    - Focusing on Templates in Oracle HTML DB





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway