Wednesday, August 17, 2011

OOPS in Oracle

Create Objects

1) Create a type ADDRESS:-
Command to be given is:-

create type ADDRESS_AD as object(street varchar2(50), city varchar2(25),state varchar2(25),zip number(10));

2) Create a PERSON type:-

create type PERSON_AD as object(name varchar2(25),address ADDRESS_AD);


3) Create a table customer:-
create a table customer(customer_id number(10), person PERSON_AD);


As you can see , in this way we have created user defined data types ADDRESS_AD and PERSON_AD which are further used to create a table named customer.


4) Inserting data in customer table:
We will write the following query:-

insert into customer values(101,PERSON_AD('Amit',ADDRESS_AD('MI Road','Jaipur','Rajasthan',302006)));


5) To see the data in the table.
give the query:-


select * from customer.
















Friday, August 12, 2011

Complex Data Types(Object Oriented Databases)

Question1) What is the need for Complex Data Types

Answer1) While dealing with object oriented databases need of complex data types are very important.
To understand complex data types, we consider an example in which address is a field in a table.
  • Entire address could be viewed as an atomic data item of type string. However this view would hide details such as the street , city, state and postal code which may be useful in certain queries.
  • But if we break address into the components, writing queries would become more complicated as we have to mention each field.
  • So the better alternative is to form structured data types, which allow a type ADDRESS with sub parts street,city,state & postal code.

 For further query visit www.gurukpo.com