Object Relational Concepts and Systems Principles User Defined Types Nested Tables Queries  References (e.g.): Ullman et a...
Motivation Objects and Relations <ul><li>Object Relational Systems </li></ul><ul><ul><li>Principles: </li></ul></ul><ul><u...
Object Relational Concepts Object types <ul><li>SQL-99: Additional Types  </li></ul><ul><ul><li>Literal types Collections:...
Object Relational Concepts Object types <ul><li>Object Types, Object Tables  </li></ul><ul><ul><ul><li>CREATE  TYPE  Movie...
Object Relational Concepts References <ul><li>REFerences </li></ul><ul><ul><li>REF types have values, can be seen by user ...
Object Relational Concepts References <ul><li>References in Oracle </li></ul><ul><ul><li>System generated OIDs , system wi...
Object Relational Concepts Object types <ul><li>…  and Tables with structured attribute types  (Non First Normal Form) </l...
Object Relational Concepts Using Object types <ul><li>Type constructors </li></ul><ul><ul><li>Each type defined by AS OBJE...
Object Relational Concepts Using Object types <ul><ul><li>Inserting into tables with structured and unstructured attribute...
Object Relational Concepts Using Object types <ul><ul><li>Inserting REFerences in two steps </li></ul></ul><ul><ul><li>How...
Object Relational Concepts References and Select <ul><ul><li>Selection of REFerenced objects </li></ul></ul><ul><ul><li>RE...
Object Relational Concepts References and Select <ul><ul><li>Accessing referenced objects: DEREF operator </li></ul></ul><...
Object Relational Concepts Select <ul><ul><li>Emulation of table select </li></ul></ul><ul><ul><li>Means: object tables ma...
Object Relational Concepts Methods <ul><li>An example using methods </li></ul><ul><ul><li>Points, lines and line length </...
Object Relational Concepts Methods <ul><ul><li>Insertion of lines  </li></ul></ul><ul><ul><li>Abstract Data Types User def...
Object Relational Concepts Methods <ul><ul><li>Adding of a method  lineLength  to Type  Line </li></ul></ul><ul><ul><li>IN...
Object Relational Concepts Methods <ul><ul><li>Implementing a method </li></ul></ul><ul><ul><li>No parameter mode in metho...
Object Relational Concepts Methods <ul><ul><li>Selection with user-defined methods </li></ul></ul><ul><ul><ul><li>SELECT l...
Object Relational Concepts Collection types   <ul><li>Collection Types </li></ul><ul><ul><li>SET, Multiset, List construct...
Object Relational Concepts   <ul><li>Collection Types in Oracle 9 </li></ul><ul><ul><li>Varrays variable number of values ...
Object Relational Concepts   <ul><ul><li>Using VARRAY  </li></ul></ul><ul><ul><li>No way to address by position e.g.  phon...
Object Relational Concepts  Nested tables   <ul><li>Nested table </li></ul><ul><ul><li>Table (type) used as column type </...
Object Relational Concepts <ul><li>Nested tables: another example </li></ul><ul><ul><ul><li>CREATE TYPE  SetNum _AS TABLE ...
Object Relational Concepts   <ul><ul><li>Nested Tables: insertion </li></ul></ul><ul><ul><li>Insert values of  'inner tabl...
Object Relational Concepts   <ul><ul><li>Querying nested tables </li></ul></ul><ul><ul><li>Querying the inner table </li><...
Object Relational Concepts   <ul><ul><li>Querying nested tables using inner tables   </li></ul></ul><ul><ul><ul><li>SELECT...
Object Relational Concepts   insert <ul><ul><li>From relations to object-relations </li></ul></ul><ul><ul><li>Suppose ther...
Object Relational Concepts Collection types: insert <ul><li>Insertion into complex structured table </li></ul><ul><li>Supp...
Object Relational Concepts   <ul><li>Inserting from a flat into a nested table </li></ul><ul><ul><ul><li>INSERT INTO Polyg...
Object Relational Concepts <ul><li>Final remarks </li></ul><ul><ul><li>No inheritance in Oracle 8i, but SQL-99.. and Oracl...
Upcoming SlideShare
Loading in …5
×

Object Relational Concepts and Systems

547 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
547
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
19
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Object Relational Concepts and Systems

  1. 1. Object Relational Concepts and Systems Principles User Defined Types Nested Tables Queries References (e.g.): Ullman et al. – book: 4.5, 9.4-5; Elmasri: ch. 13; Hohenstein, Pleßer: Oracle 9i
  2. 2. Motivation Objects and Relations <ul><li>Object Relational Systems </li></ul><ul><ul><li>Principles: </li></ul></ul><ul><ul><ul><li>Keep the goodies of RDB </li></ul></ul></ul><ul><ul><ul><li>Enhance relational systems by constructed types, inheritance, methods </li></ul></ul></ul><ul><ul><li>Supported by SQL-99 standard </li></ul></ul><ul><ul><li>Issues </li></ul></ul><ul><ul><ul><li>Technologically outdated solutions stabilized e.g. type system, baroque constructs of SQL </li></ul></ul></ul><ul><ul><ul><li>Add-on usually worse than completely new approach </li></ul></ul></ul><ul><ul><li>Important aspect: Save investment into your software by upward compatibility of.. </li></ul></ul><ul><ul><ul><li>.. DBS, application software </li></ul></ul></ul><ul><ul><li>ORDBS: Postgres, Oracle, Informix, DB2 </li></ul></ul>
  3. 3. Object Relational Concepts Object types <ul><li>SQL-99: Additional Types </li></ul><ul><ul><li>Literal types Collections: Array, List, Set… and table type Lobs (&quot;large objects&quot;): Binary (Blob), Character (CLOB) </li></ul></ul><ul><ul><li>image blob movie(2GB) </li></ul></ul><ul><ul><li>Object types A row may be an object which has attributes and can be referenced </li></ul></ul><ul><ul><ul><li>CREATE TYPE AdressType AS OBJECT ( </li></ul></ul></ul><ul><ul><ul><li>city VARCHAR(30), </li></ul></ul></ul><ul><ul><ul><li>zipCode VARCHAR(15), </li></ul></ul></ul><ul><ul><ul><li>street VARCHAR (30), </li></ul></ul></ul><ul><ul><ul><li>number VARCHAR(5), </li></ul></ul></ul><ul><ul><ul><li>country VARCHAR(15) </li></ul></ul></ul><ul><ul><ul><li>); </li></ul></ul></ul><ul><ul><ul><li>/ </li></ul></ul></ul>
  4. 4. Object Relational Concepts Object types <ul><li>Object Types, Object Tables </li></ul><ul><ul><ul><li>CREATE TYPE MovieType AS OBJECT ( </li></ul></ul></ul><ul><ul><ul><li>mId Int , </li></ul></ul></ul><ul><ul><ul><li>title VARCHAR(30), </li></ul></ul></ul><ul><ul><ul><li>director VARCHAR(25), </li></ul></ul></ul><ul><ul><ul><li>year date </li></ul></ul></ul><ul><ul><ul><li>); / </li></ul></ul></ul><ul><ul><ul><li>SQL> CREATE TABLE MovieObjects OF MovieType ; </li></ul></ul></ul>Object table Objects may only live in a table
  5. 5. Object Relational Concepts References <ul><li>REFerences </li></ul><ul><ul><li>REF types have values, can be seen by user as opposed to OO languages </li></ul></ul><ul><ul><ul><li>CREATE TABLE MovieTape ( </li></ul></ul></ul><ul><ul><ul><li>Id Int, </li></ul></ul></ul><ul><ul><ul><li>movie REF MovieType, </li></ul></ul></ul><ul><ul><ul><li>since date, </li></ul></ul></ul><ul><ul><ul><li>back date </li></ul></ul></ul><ul><ul><ul><li>); </li></ul></ul></ul>Table with object reference ud: 007 since: … back: … movie:
  6. 6. Object Relational Concepts References <ul><li>References in Oracle </li></ul><ul><ul><li>System generated OIDs , system wide unique values, even in a distributed environment </li></ul></ul><ul><ul><li>or </li></ul></ul><ul><ul><li>OIDs derived from a primary key </li></ul></ul><ul><ul><li>Relationship between system generated and primary keys have to be established by application program </li></ul></ul><ul><ul><li>Structure of OIDs implementation defined, don't use them explicitly </li></ul></ul>
  7. 7. Object Relational Concepts Object types <ul><li>… and Tables with structured attribute types (Non First Normal Form) </li></ul><ul><ul><li>No difference between structured types and object types </li></ul></ul><ul><ul><ul><li>1 Create TABLE TapeStruct ( </li></ul></ul></ul><ul><ul><ul><li>2 id INT, </li></ul></ul></ul><ul><ul><ul><li>3 format CHAR(5), </li></ul></ul></ul><ul><ul><ul><li>4 movie MovieType , </li></ul></ul></ul><ul><ul><ul><li>5 since date, </li></ul></ul></ul><ul><ul><ul><li>6* back date) </li></ul></ul></ul><ul><ul><ul><li>7 ; </li></ul></ul></ul>Object as Structured attribute <ul><ul><ul><li>SQL> CREATE OR REPLACE TYPE Foo (bar Int); </li></ul></ul></ul><ul><ul><ul><li>2 / </li></ul></ul></ul><ul><ul><ul><li>Warnung: Typ wurde mit Kompilierungsfehlern erstellt. </li></ul></ul></ul>
  8. 8. Object Relational Concepts Using Object types <ul><li>Type constructors </li></ul><ul><ul><li>Each type defined by AS OBJECT has a type constructor <objectname> </li></ul></ul><ul><ul><li>Constructor wraps the fields </li></ul></ul><ul><ul><li>e.g. MovieType(65, 'To be or not to be','Anti-war',0.5, 'Lubitsch', toDate('1942', 'YYYY')) </li></ul></ul><ul><ul><li>Used in insert statement: </li></ul></ul><ul><ul><li>And more… </li></ul></ul><ul><li>SQL> Insert INTO MovieObjects VALUES ( </li></ul><ul><ul><li>MovieType(65, 'To be or not to be', 'Lubitsch', to_Date('1942', 'YYYY'))) </li></ul></ul>
  9. 9. Object Relational Concepts Using Object types <ul><ul><li>Inserting into tables with structured and unstructured attributes (fields) </li></ul></ul><ul><ul><li>Doesn't work with REF attributes: object different from ref </li></ul></ul>SQL> INSERT INTO TapeStruct VALUES(10,'DVD', MOVIETYPE(65, 'To be or not to be', 'Lubitsch', '01.05.42'), NULL,NULL); 1 INSERT INTO MovieTape VALUES(10, 2* MOVIETYPE(65, 'To be or not to be', 'Lubitsch', '01.05.42'),NULL,NULL) 3 ; MOVIETYPE(65, 'To be or not to be', 'Lubitsch', '01.05.42'),NULL,NULL) * FEHLER in Zeile 2: ORA-00932: nicht übereinstimmende Datentypen
  10. 10. Object Relational Concepts Using Object types <ul><ul><li>Inserting REFerences in two steps </li></ul></ul><ul><ul><li>How to access fields of referenced objects? </li></ul></ul><ul><ul><li>Dereferencing: </li></ul></ul><ul><ul><li> SQL-99 with explicite dereferencing: MovieTape.movie->title Oracle implicitly (like Java) <MovieTape-alias>.movie.title </li></ul></ul>INSERT INTO MovieTape VALUES(10,NULL,NULL,NULL) 1 UPDATE MovieTape SET movie = 2 (SELECT ref(p) FROM MovieObjects p 3 WHERE p.mId = 65) 4* WHERE id=10 5 ;
  11. 11. Object Relational Concepts References and Select <ul><ul><li>Selection of REFerenced objects </li></ul></ul><ul><ul><li>REF(x): Selecting References (!) </li></ul></ul><ul><ul><li>SQL> SELECT movie FROM Movie T ape; -- movie is a REF type </li></ul></ul><ul><ul><li>MOVIE </li></ul></ul><ul><ul><li>-------------------------------------------------------------------------- </li></ul></ul><ul><ul><li>0000220208F5CD054159CB4F8681237734D7841FAF46316976DEF1481EBA83DA5399F84E12 </li></ul></ul><ul><ul><li>SQL> SELECT m .movie.title FROM MovieTape m ; </li></ul></ul><ul><ul><li>MOVIE.TITLE </li></ul></ul><ul><ul><li>------------------------------ </li></ul></ul><ul><ul><li>To be or not to be </li></ul></ul>Alias essential
  12. 12. Object Relational Concepts References and Select <ul><ul><li>Accessing referenced objects: DEREF operator </li></ul></ul><ul><ul><li>Accessing values of objects: VALUE operator </li></ul></ul><ul><ul><li>SQL> Select DEREF (p.movie) from MovieTape p; </li></ul></ul><ul><ul><li>DEREF(P.MOVIE)(MID, TITLE, DIRECTOR, YEAR) </li></ul></ul><ul><ul><li>-------------------------------------------------------- </li></ul></ul><ul><ul><li>MOVIETYPE(65, 'To be or not to be', 'Lubitsch 01.05.42') </li></ul></ul><ul><ul><li>SQL> select value(p) from movieObjects p; </li></ul></ul><ul><ul><li>VALUE(P)(MID, TITLE, DIRECTOR, YEAR) </li></ul></ul><ul><ul><li>-------------------------------------------------------- </li></ul></ul><ul><ul><li>MOVIETYPE (65, 'To be or not to be','Lubitsch', '01.05.42') </li></ul></ul><ul><ul><li>MOVIETYPE(67, 'Jurassic Parc', 'Spielberg', '01.05.97') </li></ul></ul>
  13. 13. Object Relational Concepts Select <ul><ul><li>Emulation of table select </li></ul></ul><ul><ul><li>Means: object tables may be queried like ordinary tables </li></ul></ul><ul><ul><li>But relational tables are different from object tables – even if no oo features are used </li></ul></ul><ul><ul><ul><li>select * from MovieObjects; </li></ul></ul></ul><ul><ul><ul><li>MID TITLE DIRECTOR YEAR </li></ul></ul></ul><ul><ul><ul><li>--- ------------------- ------------- -------- </li></ul></ul></ul><ul><ul><ul><li>65 To be or not to be Lubitsch 01.05.42 </li></ul></ul></ul><ul><ul><ul><li>67 Jurassic Parc Spielberg 01.05.97 </li></ul></ul></ul>
  14. 14. Object Relational Concepts Methods <ul><li>An example using methods </li></ul><ul><ul><li>Points, lines and line length </li></ul></ul><ul><ul><ul><li>SQL> create TYPE Point_T AS OBJECT ( </li></ul></ul></ul><ul><ul><ul><li>2 x NUMBER, </li></ul></ul></ul><ul><ul><ul><li>3 y NUMBER </li></ul></ul></ul><ul><ul><ul><li>4 ); </li></ul></ul></ul><ul><ul><ul><li>5 / </li></ul></ul></ul><ul><ul><ul><li>SQL> CREATE TYPE Line_T AS OBJECT ( </li></ul></ul></ul><ul><ul><ul><li>2 end1 Point_T, </li></ul></ul></ul><ul><ul><ul><li>3 end2 Point_T </li></ul></ul></ul><ul><ul><ul><li>4 (; </li></ul></ul></ul><ul><ul><ul><li>5 / </li></ul></ul></ul><ul><ul><ul><li>SQL> CREATE TABLE Lines ( </li></ul></ul></ul><ul><ul><ul><li>2 lineId INT, </li></ul></ul></ul><ul><ul><ul><li>3 line Line_T); -- value, no REF </li></ul></ul></ul>
  15. 15. Object Relational Concepts Methods <ul><ul><li>Insertion of lines </li></ul></ul><ul><ul><li>Abstract Data Types User defined type specifies fields and the signature of methods (&quot;Member functions&quot;) </li></ul></ul><ul><ul><li>Implementation of body separately </li></ul></ul><ul><ul><ul><li>SQL> INSERT INTO Lines </li></ul></ul></ul><ul><ul><ul><li>2 VALUES (10, Line_T ( </li></ul></ul></ul><ul><ul><ul><li>3 Point_T(0.0,0.0), </li></ul></ul></ul><ul><ul><ul><li>4 Point_T(1.0, 2.0) </li></ul></ul></ul><ul><ul><ul><li>5 ) </li></ul></ul></ul><ul><ul><ul><li>6 ); </li></ul></ul></ul>
  16. 16. Object Relational Concepts Methods <ul><ul><li>Adding of a method lineLength to Type Line </li></ul></ul><ul><ul><li>IN, OUT and INOUT parameter in signature </li></ul></ul><ul><ul><li>Pragma &quot;Write No Database State&quot; (WNDS) needed if function is to be used in SELECTs </li></ul></ul><ul><ul><ul><li>SQL> ALTER TYPE Line_T REPLACE AS OBJECT( </li></ul></ul></ul><ul><ul><ul><li>2 end1 Point_T, </li></ul></ul></ul><ul><ul><ul><li>3 end2 Point_T, </li></ul></ul></ul><ul><ul><ul><li>4 MEMBER FUNCTION lineLength (scale IN NUMBER) RETURN NUMBER, </li></ul></ul></ul><ul><ul><ul><li>5 PRAGMA RESTRICT_REFERENCES (lineLength, WNDS) </li></ul></ul></ul><ul><ul><ul><li>6 ); </li></ul></ul></ul>
  17. 17. Object Relational Concepts Methods <ul><ul><li>Implementing a method </li></ul></ul><ul><ul><li>No parameter mode in method implementation </li></ul></ul><ul><ul><ul><li>CREATE TYPE BODY Line_T AS </li></ul></ul></ul><ul><ul><ul><li>MEMBER FUNCTION lineLength (scale NUMBER) RETURN NUMBER IS </li></ul></ul></ul><ul><ul><ul><li>BEGIN </li></ul></ul></ul><ul><ul><ul><li>RETURN </li></ul></ul></ul><ul><ul><ul><li>scale * </li></ul></ul></ul><ul><ul><ul><li>SQRT((SELF.end1.x – SELF.end2.x)*(SELF.end1.x-SELF.end2.x) + </li></ul></ul></ul><ul><ul><ul><li>(SELF.end1.y-SELF.end2.y)* (SELF.end1.y-SELF.end2.y) </li></ul></ul></ul><ul><ul><ul><li>); </li></ul></ul></ul><ul><ul><ul><li>END; </li></ul></ul></ul><ul><ul><ul><li>END; </li></ul></ul></ul><ul><ul><ul><li>/ </li></ul></ul></ul>
  18. 18. Object Relational Concepts Methods <ul><ul><li>Selection with user-defined methods </li></ul></ul><ul><ul><ul><li>SELECT lineId, l.line. lineLength (1.0) </li></ul></ul></ul><ul><ul><ul><li>FROM Lines l; </li></ul></ul></ul><ul><ul><ul><li>LINEID L.LINE.LINELENGTH(1.0) </li></ul></ul></ul><ul><ul><ul><li>------ ---------------------- </li></ul></ul></ul><ul><ul><ul><li>10 2,23606798 </li></ul></ul></ul><ul><ul><ul><li>30 ,282842712 </li></ul></ul></ul><ul><ul><ul><li>SELECT l.line.end1, l.line.end2 FROM Lines l </li></ul></ul></ul><ul><ul><ul><li>WHERE l.line. lineLength (1) > 1.5; </li></ul></ul></ul><ul><ul><ul><li>LINE.END1(X, Y) LINE.END2(X, Y) </li></ul></ul></ul><ul><ul><ul><li>----------------------------------------------- </li></ul></ul></ul><ul><ul><ul><li>POINT_T(0, 0) POINT_T(1, 2) </li></ul></ul></ul>
  19. 19. Object Relational Concepts Collection types <ul><li>Collection Types </li></ul><ul><ul><li>SET, Multiset, List constructors for primitive and constructed types e.g. Phones SET (VARCHAR(20)) Polygon LIST (Point_T) </li></ul></ul><ul><ul><li>Value of constructed coolection type may be regarded as a table </li></ul></ul><ul><ul><li>Non First Normal Form Relations </li></ul></ul>Name Phones …. Abel (432,8764) … … . id polygon …. <ul><li>… </li></ul>[(432,874) (101,200) (111,343)] 13
  20. 20. Object Relational Concepts <ul><li>Collection Types in Oracle 9 </li></ul><ul><ul><li>Varrays variable number of values of some type </li></ul></ul><ul><ul><ul><li>CREATE TYPE ExtentT as VARRAY(4) OF Int; </li></ul></ul></ul><ul><ul><ul><li>CREATE OR REPLACE TYPE Address_T AS OBJECT ( </li></ul></ul></ul><ul><ul><ul><li>zipcode CHAR(6), </li></ul></ul></ul><ul><ul><ul><li>ciy VARCHAR(20), </li></ul></ul></ul><ul><ul><ul><li>street VARCHAR(25), </li></ul></ul></ul><ul><ul><ul><li>no CHAR(5)); </li></ul></ul></ul><ul><ul><ul><li>CREATE TABLE PhoneBook ( </li></ul></ul></ul><ul><ul><ul><li>name VARCHAR(30), </li></ul></ul></ul><ul><ul><ul><li>firstName VARCHAR(20), </li></ul></ul></ul><ul><ul><ul><li>addr Address_T, </li></ul></ul></ul><ul><ul><ul><li>phones ExtentT); </li></ul></ul></ul>
  21. 21. Object Relational Concepts <ul><ul><li>Using VARRAY </li></ul></ul><ul><ul><li>No way to address by position e.g. phones[2] </li></ul></ul><ul><ul><ul><li>INSERT INTO PhoneBook VALUES( </li></ul></ul></ul><ul><ul><ul><li>'Abel', 'Hendrik', ADDRESS_T('12347', 'Berlin', 'Takustr.','9'), </li></ul></ul></ul><ul><ul><ul><li>ExtentT(2347, 1139)); </li></ul></ul></ul><ul><ul><ul><li>SELECT b.name, b.addr.street, b.phones </li></ul></ul></ul><ul><ul><ul><li>FROM PhoneBook b </li></ul></ul></ul><ul><ul><ul><li>WHERE 2347 IN (SELECT * FROM TABLE (b.phones)); </li></ul></ul></ul><ul><ul><ul><li>NAME ADDR.STREET PHONES </li></ul></ul></ul><ul><ul><ul><li>--------------------------------- </li></ul></ul></ul><ul><ul><ul><li>Abel Takustr. EXTENSION_T(2347, 1139) </li></ul></ul></ul>Cast of a varray to a table
  22. 22. Object Relational Concepts Nested tables <ul><li>Nested table </li></ul><ul><ul><li>Table (type) used as column type </li></ul></ul><ul><ul><li>Restriction: only one level of nesting (Oracle 9i: no restriction) </li></ul></ul><ul><ul><ul><li>CREATE TYPE Polygon_T AS TABLE OF Point_T; </li></ul></ul></ul><ul><ul><ul><li>CREATE TABLE Polygons ( </li></ul></ul></ul><ul><ul><ul><li>pid CHAR(5), </li></ul></ul></ul><ul><ul><ul><li>points Polygon_T) </li></ul></ul></ul><ul><ul><ul><li>NESTED TABLE points STORE AS PointsTab ; </li></ul></ul></ul>Stored outside table Polygons , Has to be made explicit
  23. 23. Object Relational Concepts <ul><li>Nested tables: another example </li></ul><ul><ul><ul><li>CREATE TYPE SetNum _AS TABLE OF Number; </li></ul></ul></ul><ul><ul><ul><li>CREATE TYPE B AS OBJECT (b1: INTEGER, b2 SetNum); </li></ul></ul></ul><ul><ul><ul><li>CREATE TYPE SetB AS TABLE OF B; </li></ul></ul></ul><ul><ul><ul><li>CREATE TABLE Rel (a1 NUMBER, a2 SetB) </li></ul></ul></ul><ul><ul><ul><li>NESTED TABLE a2 STORE AS TabSetB </li></ul></ul></ul><ul><ul><ul><li>(Nested Table COLUMN_VALUE STORE AS TabSetNum); </li></ul></ul></ul>1 2 21 22 11 111 112 Rel a1: NUMBER, a2: SetB
  24. 24. Object Relational Concepts <ul><ul><li>Nested Tables: insertion </li></ul></ul><ul><ul><li>Insert values of 'inner table' as a list of constructed values (here of type Point_T ) </li></ul></ul><ul><ul><ul><li>INSERT INTO Polygons VALUES( </li></ul></ul></ul><ul><ul><ul><li>'squ01', Polygon_T(Point_T(0.0, 0.0), Point_T(0.0, 1.0), </li></ul></ul></ul><ul><ul><ul><li>Point_T(1.0, 0.0), Point_T(1.0, 1.0) </li></ul></ul></ul><ul><ul><ul><li>) </li></ul></ul></ul><ul><ul><ul><li>); </li></ul></ul></ul>
  25. 25. Object Relational Concepts <ul><ul><li>Querying nested tables </li></ul></ul><ul><ul><li>Querying the inner table </li></ul></ul><ul><ul><ul><li>SELECT points </li></ul></ul></ul><ul><ul><ul><li>FROM Polygons </li></ul></ul></ul><ul><ul><ul><li>WHERE pid LIKE 'squ%'; </li></ul></ul></ul><ul><ul><ul><li>-- finds all squares </li></ul></ul></ul><ul><ul><ul><li>SELECT ss.x </li></ul></ul></ul><ul><ul><ul><li>FROM THE (SELECT points -- keyword THE </li></ul></ul></ul><ul><ul><ul><li>FROM Polygons </li></ul></ul></ul><ul><ul><ul><li>WHERE pid ='squ01' </li></ul></ul></ul><ul><ul><ul><li>) ss -- Alias for inner </li></ul></ul></ul><ul><ul><ul><li>WHERE ss.x = ss.y; -- table -- qualification </li></ul></ul></ul>Must identify exactly one row
  26. 26. Object Relational Concepts <ul><ul><li>Querying nested tables using inner tables </li></ul></ul><ul><ul><ul><li>SELECT t.pid FROM Polygons t </li></ul></ul></ul><ul><ul><ul><li>WHERE EXISTS </li></ul></ul></ul><ul><ul><ul><li>(SELECT ss.x FROM </li></ul></ul></ul><ul><ul><ul><li>TABLE(SELECT points </li></ul></ul></ul><ul><ul><ul><li>FROM Polygons t2 </li></ul></ul></ul><ul><ul><ul><li>WHERE t2.pid =t.pid </li></ul></ul></ul><ul><ul><ul><li>) ss </li></ul></ul></ul><ul><ul><ul><li>WHERE ss.x = ss.y) </li></ul></ul></ul><ul><ul><ul><li>AND pid <> 'squ01'; </li></ul></ul></ul>Inner qualification on table value Select one row in polygons and select a table value (points) Additional outer qualification predicate
  27. 27. Object Relational Concepts insert <ul><ul><li>From relations to object-relations </li></ul></ul><ul><ul><li>Suppose there is a flat table </li></ul></ul><ul><ul><ul><li>CREATE TABLE LinesFlat( </li></ul></ul></ul><ul><ul><ul><li>id INT, </li></ul></ul></ul><ul><ul><ul><li> x1 NUMBER,y1 NUMBER,x2 NUMBER,y2 NUMBER </li></ul></ul></ul><ul><ul><ul><li>); </li></ul></ul></ul><ul><ul><ul><li>INSERT INTO Lines </li></ul></ul></ul><ul><ul><ul><li>SELECT id, Line_T(Point_T(x1,y1), </li></ul></ul></ul><ul><ul><ul><li>Point_T(x2,y2)) </li></ul></ul></ul><ul><ul><ul><li>FROM LinesFlat; </li></ul></ul></ul>Insertion, values supplied by SELECT, constructed by appropriate type
  28. 28. Object Relational Concepts Collection types: insert <ul><li>Insertion into complex structured table </li></ul><ul><li>Suppose, there is a flat Polygon table </li></ul><ul><li>Steps to insert all the points with name ' triangle ' into the Polygon Table with nested table attribute points </li></ul><ul><ul><li>Query PolyFlat to get all points belonging to triangle </li></ul></ul><ul><ul><li>Turn the collection of answers into relation using keyword MULTISET </li></ul></ul><ul><ul><li>Turn relation into a Polygon_T value by CAST …AS Polygon_T </li></ul></ul><ul><ul><ul><li>CREATE TABLE PolyFlat ( </li></ul></ul></ul><ul><ul><ul><li>name VARCHAR2(20), </li></ul></ul></ul><ul><ul><ul><li>x NUMBER, y NUMBER </li></ul></ul></ul><ul><ul><ul><li>); </li></ul></ul></ul>
  29. 29. Object Relational Concepts <ul><li>Inserting from a flat into a nested table </li></ul><ul><ul><ul><li>INSERT INTO Polygons VALUES('square', </li></ul></ul></ul><ul><ul><ul><li>CAST( </li></ul></ul></ul><ul><ul><ul><li>MULTISET(SELECT x, y </li></ul></ul></ul><ul><ul><ul><li>FROM PolyFlat </li></ul></ul></ul><ul><ul><ul><li>WHERE name = 'square' </li></ul></ul></ul><ul><ul><ul><li>) </li></ul></ul></ul><ul><ul><ul><li>AS Polygon_T </li></ul></ul></ul><ul><ul><ul><li>) ); </li></ul></ul></ul>
  30. 30. Object Relational Concepts <ul><li>Final remarks </li></ul><ul><ul><li>No inheritance in Oracle 8i, but SQL-99.. and Oracle >= 9 </li></ul></ul><ul><ul><li>Object-relational technology is mature </li></ul></ul><ul><ul><li>Lack of standards prevents heavy usage – despite SQL-99 </li></ul></ul><ul><ul><li>Might improve the 'impedance mismatch' between programming languages and relational database while keeping the advantages of tabular data </li></ul></ul><ul><ul><li>Use of ORDB in O/R mapping?? </li></ul></ul><ul><ul><li>The more concepts – the more implementations – the more solutions – the more bugs? </li></ul></ul><ul><ul><li>Does the base Principle of RDM still hold: Keep it simple, stupid! </li></ul></ul>

×