1

I successfully created an EmployeeType in Oracle 11g with the following atrributes;

emp_id   VARCHAR2(5)
title   VARCHAR(15)
firstname VARCHAR(20)
surname   VARCHAR(20)
address Addresstype
tel_no  ARRAY(3) of VARCHAR(15)
get_address() VARCHAR2()

and was told to create DepartmentType in Oracle 11g with the following attributes

dept_id  VARCHAR2(3)
location AddressType
manager  REF Employee

but my problem now is I don't know how to use the object-relational REF construct to define object-references between the two tables for relating Departments to Employees so that I can create table which will store department details and insert rows.

Justin Cave
  • 227,342
  • 24
  • 367
  • 384

1 Answers1

2

You can use some ORM (Object Relational Mapping) frameworks you can read about it here

What is an Object-Relational Mapping Framework?

That is a huge topic, or you can manage to find a way to do it yourself, but what you must know is that relational database are just rows with data, nothing to do with Object Oriented Object, you can take it as a way to store data.

I hope this helps.

Community
  • 1
  • 1
Mehdi Karamosly
  • 5,388
  • 2
  • 32
  • 50
  • I created the DepartmentType with the following command CREATE TYPE DepartmentType as OBJECT ( dept_id VARCHAR2(3), locations AddressType, manager REF EmployeeType )NOT FINAL; but when I tried using the following command INSERT INTO department VALUES (D01, AddressType(47, 'Canal Street', 'Manchester', 'MR8 9WR'), (SELECT REF(e) FROM EMPLOYEE e WHERE emp_id = 2)); to insert rows into the department table I got an error saying 'Column not allowed here'. Please I really need solution on this problem. – chidoskychidosky Feb 23 '13 at 02:16
  • @chidoskychidosky Your insert works for me if I add single quotation marks around `D01`. – Jon Heller Feb 23 '13 at 03:26
  • @ Jonearles Thank you very much. The way I referenced the two tables is it correct? – chidoskychidosky Feb 23 '13 at 21:29
  • Please how do I join the Employee and department table by the use object references. – chidoskychidosky Feb 23 '13 at 22:30
  • How do I display the contents in the array in the Employee table above? – chidoskychidosky Feb 23 '13 at 22:33
  • 1
    To answer your join question start reading from : `Creating References to View Objects` you will have to use `REF ` modifier http://docs.oracle.com/cd/A87860_01/doc/appdev.817/a76976/adobjvew.htm But I think your making it harder by dealing with object references. – Mehdi Karamosly Feb 25 '13 at 17:37