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.
















No comments:

Post a Comment