Oracle
  Home arrow Oracle arrow Database Interaction with PL/SQL: OBJECT and OBJECT
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: OBJECT and OBJECT
By: Jagadish Chatarji
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 24
    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:
      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: OBJECT and OBJECT
    ( Page 1 of 4 )

    Jagadish Chatarji has been writing about database interactions with Oracle PL/SQL. The last part examined using TABLE, RECORD and NESTED TABLES with PL/SQL. This one now introduces OBJECT TYPE in Oracle, and explains both SQL and PL/SQL ways of working with OBJECTs. This article is the fourth in the series.

    Please note that all the examples in this series have been tested only with Oracle 10g, not with all the previous versions of Oracle.  I suggest you to refer the documentation of respective version you are using if any of the programs failed to execute.

    Introduction to OBJECT TYPE:

    It is worthwhile to introduce the concept of OBJECT here, as we can also work with OBJECTs in PL/SQL pleasantly.  I will not go much into the depth of OOPS with MEMBER methods etc at this moment.  My up-coming articles will look into the depth of OOPS in Oracle 10g.  For now we will just concentrate on minimum basics of OBJECT together with PL/SQL.

    For the time being, just consider OBJECT type as similar to RECORD type in PL/SQL (RECORD was explained in part-2 and part-3 of my articles).  RECORD type works only in PL/SQL.  But OBJECT type gets stored in database and can be used in both SQL and PL/SQL (without redefining it in PL/SQL).

    Let us consider the following example.

    CREATE TYPE t_experience AS OBJECT
    (
                Ename          varchar2(20),
                CompanyName    varchar2(20),
                Position       varchar2(20),
                NoOfYears      number(2)
    );
    /

    The above script just creates only an OBJECT TYPE (not a table).  Remember it is TYPE (which means something like a datatype).  The OBJECT TYPE can be used to create a table based on its definition.

    CREATE TABLE Employees OF t_experience;

    The above statement creates a new table named ‘Employees’ with exactly the same structure of ‘t_experience’.  The following statement inserts a row based on the OBJECT TYPE structure.

    insert into employees values
     
    ('jag','xyz company','software engineer',5);

    I don’t think you would find any difference between above statement and ordinary INSERT, as they work the same way.  Even though the above INSERT is valid, for better readability, it is always suggested to issue the above statement as follows:

    insert into employees values (t_experience('jag','xyz
      company','software engineer',5));

    The only difference is that we are enclosing all the values into the specification of OBJECT TYPE ‘t_experience’.  All the other DML commands (INSERT, UPDATE, DELETE and SELECT) can be issued just like ordinary SQL statements without any difference.



     
     
    >>> 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 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek