4

I have created an object type(address-city,state) in Oracle 10g .Then table cust_contact contains field of type address.Can anyone please provide SQL query to insert and retrieve values from this table including the type?

3 Answers 3

4

Selection is easy. Just include the type column in the query projection. Assuming that the ADDRESS column is called contact_address:

select id, contact_name, contact_address
from cust_contact
/

With inserts you need to specify the type in the statement:

insert into cust_contact values
    (some_seq.nextval
     , 'MR KNOX'
     , address(34, 'Main Street', 'Whoville', 'SU')
    )
/
Sign up to request clarification or add additional context in comments.

Comments

0

You can also use the "." syntax when retrieving columns:

select c.contact_address.city from cust_contact c;

Please note that if cust_contact is a table of objects, then you must use the table alias "c".

Comments

0

for example : first create type object say as address ,for this synatx or query is used: create type address_ty as object(Street varchar2(50),City char(10),Zip number(6));

now use this address_ty as datatype in the time of table creation for example: create table Example(emp_name varchar2(10),emp_id number(10),address address_ty); this will create table Example having Address as address_ty as a datatype..

Now insert into Values In Example Table Insert Into example Values('Sandeep Kumar',595,address_ty('Snap on sector 126','Noida',201301);

tHANX....

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.