Oracle
  Home arrow Oracle arrow Page 6 - Working With Oracle on Windows: Part 2
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
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

Working With Oracle on Windows: Part 2
By: Ben Shepherd
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 13
    2003-03-04

    Table of Contents:
  • Working With Oracle on Windows: Part 2
  • Databases
  • Relationships
  • Structuring your database
  • Tables in Oracle
  • User Defined Schema Objects
  • Conclusion

  • 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


    Working With Oracle on Windows: Part 2 - User Defined Schema Objects


    (Page 6 of 7 )

    The DDL (i.e. Data Definition Library) contains the set of commands that allow us to create, drop tables and establish new schema objects. To create an object we can type the following,

    CREATE OR REPLACE TYPE firstType AS OBJECT
    (
     v_id               NUMBER,
     v_firstName     VARCHAR2(25),
     v_surname      VARCHAR2(30)
    )
    /

    We have now created a new schema object in the DDL. Now to create a table we can type,

    CREATE TABLE firstTable of firstType
    /


    This will create the same table the only difference is that the DDL doesn’t create an object this time. The reason why you would create a schema object is so that you can create a number table that has the same attributes. Another reason why you’d use schema objects is the simplicity of inputting data into a table.

    Let’s input data into our firstTable table using DML (i.e. Data Manipulation Language). We could simply insert data like this

    INSERT INTO firstTable VALUES (1,’Kim’,’Tyson’);

    How could we use schema objects for inputting data into a table? The answer is again very simple. We create a schema object and embedded the user defined schema object into the table.

    CREATE OR REPLACE TYPE t_address AS OBJECT
    (
     v_streetNumber     NUMBER,
     v_streetName       VARCHAR2(30),
     v_citySuburb        VARCHAR2(30),
     v_state               VARCHAR2(4),
     v_postCode          NUMBER  
    )

    CREATE TABLE secondTable
    (
     v_customerId         NUMBER,
     v_homeAddress      t_address,
     v_workAddress       t_address
    )

    Now we may insert data using the schema objects as follows,

    INSERT INTO secondTable VALUES
    ( 0001,
    t_address(1, ‘Jackson Street’, ‘Sydney’, ‘NSW’, 2000),
    t_address(3, ‘Jackson Street’, ‘Sydney’, ‘NSW’, 2000)
    )

    Did you notice something apart from the fact that this poor guy lives next door from where he works? Yes, you can insert schema object into a field.

    More Oracle Articles
    More By Ben Shepherd


     

    ORACLE ARTICLES

    - Partitioning in Oracle. What? Why? When? Who...
    - Datatypes Used in Oracle 9i
    - Creating a Database in Oracle 9i
    - Oracle with Doctor Janusz Getta
    - Working With Oracle on Windows: Part 3
    - Working With Oracle on Windows: Part 2







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