Beruflich Dokumente
Kultur Dokumente
3 4
Introduction
! Context:
(Oracle's) – the OO paradigm supports more powerful
Object-Relational Model functionality than the relational paradigm
– RDBMS products and SQL hold a large market
share and users are quite familiar with the
approach
– The natural evolution trend is to enhance
relational technology towards support of the best
Latest technology ! of OO features compatible with it:
! Abstract data types; inheritance; functions; object
identity
! Evolution but not a Revolution :
– relational + OO = Object Relational
5 5 6
Upgrading SQL Upgrading the data model
! SQL2: relational DBMS ! Logical level data modeling
! SQL3: OR DBMS: ! Always based on a tabular structure
– SQL2 + ! Three kinds of tables:
! OO extensions – 1FN tables (traditional)
! Multi-media – NF2 tables (non-1NF: NFNF): tables holding structured elements
! Space – Tables of objects
! Temporal Series
! User-defined structured value domains: Type
! …
– To describe complex and multivalued structures
! SQL3 is compatible with SQL2: – To create objects: <oid, value> pairs
Seamless evolution – To define methods
! Types can be organized into an inheritance hierarchy
! Composition links (reference attributes) can be defined
using the REF constructor
7 8
11 12
OBJECTS Creating complex values
! "OBJECT" Types allow creating complex
monovalued structures which can be used to: ! CREATE TYPE Taddress AS OBJECT
– Create a complex value ( street VARCHAR(20), number VARCHAR(4), city
– Create an object with a complex value: (oid, complex value) VARCHAR(20), ZIP CHAR(4) )
! CREATE TYPE typename AS OBJECT ! CREATE TABLE Person (avs CHAR(11), name
( att1 typename1, att2 typename2, …, VARCHAR(20), forenames Tforenames, adr Taddress )
<definition of methods> )
– typenamei :
! Any usual SQL type (CHAR, VARCHAR, NUMBER…)
VARRAY AS OBJECT
! Any user-defined type multivalued monovalued
! Only for NESTED TABLE types: CREATE TABLE Person (avs CHAR(11),
– SELECT p!address!city name VARCHAR(20), tel Tphones)
NESTED TABLE tel STORE AS PhonesTable
FROM Person p a specific value within the collection can be accessed either:
WHERE p!avs = 12345123451
– using traditional SQL clauses (element IN collection, EXISTS collection)
SELECT p FROM Person p
WHERE '0216933645' IN (SELECT * FROM TABLE (p!tel))
– or using a variable associated to the nested table
SELECT p FROM Person p, TABLE(p!tel) t
WHERE t!COLUMN_VALUE = '0216933645'
19 20
Referencing
To store persons with the apartment they live in:
1) CREATE TYPE Tapartment AS OBJECT (……)
Identity and Reference ! 2a) CREATE TABLE Person1 (avs CHAR(11), name VARCHAR(20) ,
forenames Tforenames, livesIn Tapartment)
– livesIN: structured value. The apartment value is within the person value.
Person Apartment
livesIn 0:1
avs name forenames A# type surface nbRooms
21 21 22
Methods
! Methods are defined in OBJECT types
Methods – CREATE TYPE Taddress AS OBJECT ( street VARCHAR(20),
number VARCHAR(4), city VARCHAR(20), ZIP CHAR(4) ,
MEMBER FUNCTION housenumber RETURN INTEGER)
END housenumber;
END;
29 29 30
Method Definitiom Method invocation
! CREATE TYPE typename AS OBJECT
( declaration of attributes , ! Methods are referenced using the same dot
declaration of signatures of methods ) notation as for complex structures;
! Signature of a method: – CREATE TABLE Student
– MEMBER FUNCTION methodName (name CHAR(30), homeaddress Taddress)
( parameter1 [ IN / OUT ] type1 , ….) RETURN typen
– MEMBER PROCEDURE methodName
( parameter1 [ IN / OUT ] type1 , ….) – SELECT st housenumber()
!
Conclusion
! OR is compatible with relational (i.e. you can run a
relational DB using an OR DBMS)
! OR adds new OO-flavour features:
– User-defined Data Types
– Complex Types
– Composite
– Collections
– References
– Methods
– Oids
– OBJECT Type hierarchies with (optionally) corresponding
table hierarchies
! Still missing: inverse links
! Data manipulation sometimes non-intuitive
41