1 Advanced Databases (CM036): Lecture # 5 ( Object-Relational and Nested-Relational Databases) Introduction to Object-Relational features of Oracle 9i.

Slides:



Advertisements
Similar presentations
Oracle Object-Relational Model. - Structures : tables, views, indexes, etc. - Operations : actions that manipulate data stored in structures - Integrity.
Advertisements

AN INTRODUCTION TO PL/SQL Mehdi Azarmi 1. Introduction PL/SQL is Oracle's procedural language extension to SQL, the non-procedural relational database.
PL/SQL. Introduction to PL/SQL PL/SQL is the procedure extension to Oracle SQL. It is used to access an Oracle database from various environments (e.g.
Professor: Dr. Shu-Ching Chen TA: Hsin-Yu Ha.  Objects  Varray  Nested Table  Transaction Control Language(TCL)
SQL Lecture 10 Inst: Haya Sammaneh. Example Instance of Students Relation  Cardinality = 3, degree = 5, all rows distinct.
Winter 2002Arthur Keller – CS 18012–1 Schedule Today: Feb. 19 (T) u Object-Relational Systems. u Read Sections 4.5, Assignment 5 due. Feb. 21.
Dec 4, 2003Murali Mani SQL B term 2004: lecture 14.
Oracle Objects Object Oriented Database Approach.
Chapter 9: Object-Relational Databases
Fall 2001Arthur Keller – CS 18014–1 Schedule Nov. 13 (T) Object-Relational, O-R Queries. u Read Sections 4.5, Assignment 6 due. (No office hours.)
Database Modifications A modification command does not return a result as a query does, but it changes the database in some way. There are three kinds.
Fundamentals, Design, and Implementation, 9/e Chapter 7 Using SQL in Applications.
Fundamentals, Design, and Implementation, 9/e Chapter 16 Object-Oriented Database Processing.
Introduction to PL/SQL Lecture 0 – Self Study Akhtar Ali.
1 Relational Data Model CS 157B Nidhi Patel. 2 What is a Data Model? A notation for describing data or information A notation for describing data or information.
Database Systems Lecture 5 Natasha Alechina
IST Databases and DBMSs Todd S. Bacastow January 2005.
Advanced Database CS-426 Week 2 – Logic Query Languages, Object Model.
Object-Based Databases. 2 Complex Data Types and Object Orientation Structured Data Types and Inheritance in SQL Table Inheritance Array and Multiset.
©Silberschatz, Korth and SudarshanDatabase System Concepts.
Structured Query Language (SQL) A2 Teacher Up skilling LECTURE 2.
PL / SQL P rocedural L anguage / S tructured Q uery L anguage Chapter 7 in Lab Reference.
Database System Concepts ©Silberschatz, Korth and Sudarshan Database System Concepts Chapter 9: Object-Based Databases.
The Relational Model These slides are based on the slides of your text book.
Chapter 4 The Relational Model.
Object Query Language (OQL) and Language Binding
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 7-1 David M. Kroenke’s Chapter Seven: SQL for Database Construction and.
DBMS Lecture 9  Object Database Management Group –12 Rules for an OODBMS –Components of the ODMG standard  OODBMS Object Model Schema  OO Data Model.
Relational Data Model, R. Ramakrishnan and J. Gehrke with Dr. Eick’s additions 1 The Relational Model Chapter 3.
The Relational Model. Review Why use a DBMS? OS provides RAM and disk.
PL/SQLPL/SQL Oracle10g Developer: PL/SQL Programming Chapter 11 Introduction to Dynamic SQL and Object Technology.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Intro to Relational.
1 Object-Relational Databases User-Defined Types Nested Tables.
Oracle Data Definition Language (DDL) Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008.
ADVANCED DATABASE SYSTEMS DR. FATEMEH AHMADI- ABKENARI SEPTEMBER Object Databases.
Lecture2: Database Environment Prepared by L. Nouf Almujally & Aisha AlArfaj 1 Ref. Chapter2 College of Computer and Information Sciences - Information.
Winter 2006Keller, Ullman, Cushing12–1 Object-Relational Systems Object-oriented ideas enter the relational world. u Keep relation as the fundamental abstraction.
1 Structured Query Language (SQL). 2 Contents SQL – I SQL – II SQL – III SQL – IV.
1 Chapter 1 Introduction. 2 Introduction n Definition A database management system (DBMS) is a general-purpose software system that facilitates the process.
Lecture2: Database Environment Prepared by L. Nouf Almujally 1 Ref. Chapter2 Lecture2.
© 2002 by Prentice Hall 1 David M. Kroenke Database Processing Eighth Edition Chapter 18 Object- Oriented Database Processing.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com ICOM 5016 – Introduction.
Object-Relational SQL CIS 4301 Lecture Notes 4/20/2006.
1 Advanced Databases (CM036) – Lecture # 12: The ODMG Standard for Object Databases Object Query Language (OQL) & Language Binding Advanced Database Technologies.
SQL Fundamentals  SQL: Structured Query Language is a simple and powerful language used to create, access, and manipulate data and structure in the database.
Commercial RDBMSs Access and Oracle. Access DBMS Architchecture  Can be used as a standalone system on a single PC: -JET Engine -Microsoft Data Engine.
1 CS457 Object-Oriented Databases Chapters as reference.
Dec 8, 2003Murali Mani Constraints B term 2004: lecture 15.
Chapter 2: Intro to Relational Model. 2.2 Example of a Relation attributes (or columns) tuples (or rows)
Chapter 2 Object-Relational DBMSs Chapter 28 in Textbook.
Object Relational Features
© D. Wong Security and User Authorization in SQL 8.7 pp. 410  Authorization ID = user name  Special authorization ID: PUBLIC  Privileges for:
Object-Relational Model. Review: Data Models Hierarchical Network ER (Pure) Relational (Pure) Object-oriented (ODMG) Object-relational (since SQL:1999)
Lecture 16 Object relational databases. 2 Objectives How relational model has been extended to support advanced database applications. Features proposed.
Mining real world data RDBMS and SQL. Index RDBMS introduction SQL (Structured Query language)
ITS232 Introduction To Database Management Systems Siti Nurbaya Ismail Faculty of Computer Science & Mathematics, Universiti Teknologi MARA (UiTM), Kedah.
Experience with XML Schema Ashok Malhotra Schema Usage  Mapping XML Schema and XML documents controlled by the Schema to object classes and instances.
Text TCS INTERNAL Oracle PL/SQL – Introduction. TCS INTERNAL PL SQL Introduction PLSQL means Procedural Language extension of SQL. PLSQL is a database.
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Chapter 12 Outline Overview of Object Database Concepts Object-Relational Features Object Database.
Chapter 1: Introduction. 1.2 Database Management System (DBMS) DBMS contains information about a particular enterprise Collection of interrelated data.
CS 440 Database Management Systems Stored procedures & OR mapping 1.
Chapter 3 The Relational Model. Why Study the Relational Model? Most widely used model. Vendors: IBM, Informix, Microsoft, Oracle, Sybase, etc. “Legacy.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
1 CS122A: Introduction to Data Management Lecture #4 (E-R  Relational Translation) Instructor: Chen Li.
CS422 Principles of Database Systems Object-Oriented Features in DBMS Chengyu Sun California State University, Los Angeles.
Object-Relational and Nested-Relational Databases By Dr. Akhtar Ali
Object-Relational DBMSs
Chapter 10 Oracle9i Developer: PL/SQL Programming
Structured Types (9-12-2) Structured types allow composite attributes of E-R diagrams to be represented directly. Unnamed row types can also be used in.
Object – relational database
Presentation transcript:

1 Advanced Databases (CM036): Lecture # 5 ( Object-Relational and Nested-Relational Databases) Introduction to Object-Relational features of Oracle 9i Oracle9i Application Developer's Guide - Object-Relational Features, Release 2 (9.2) appdev.920/a96594/toc.htm By Dr. Akhtar Ali Extensions to Relational Databases

2 Advanced Databases (CM036): Lecture # 5 ( Object-Relational and Nested-Relational Databases) Oracle Object-Relational Features User Defined Object Types (UDOT) –A type having attributes and methods Objects are instances of UDOTs. Type Inheritance –You can specialize an object type by creating subtypes that have some added, differentiating feature, e.g. attributes or/and methods Object Tables –An object table is a special kind of table in which each row represents an object. Object Views –An object view is a way to access relational data using object-relational features. –It lets you develop object-oriented applications without changing the underlying relational schema.

3 Advanced Databases (CM036): Lecture # 5 ( Object-Relational and Nested-Relational Databases) Oracle Object-Relational Features … REF Data type –A REF is a logical "pointer" to a row object. REF s and collections of REF s model associations among objects, particularly many-to-one/many-to-many relationships. –REF s provide an easy mechanism for navigating between objects. Collections –Two collection data types: varrays and nested tables –A varray is an ordered collection of elements: the position of each element has an index number, and you use this number to access particular elements. –A nested table can have any number of elements: no maximum is specified in the definition of the table; also, the order of the elements is not preserved. –Elements of a nested table are actually stored in a separate storage table.

4 Advanced Databases (CM036): Lecture # 5 ( Object-Relational and Nested-Relational Databases) User Defined Object Types (UDOT) An Object type declaration is like a record or tuple construct. Methods can be associated with a UDOT. Object types can be used as Domain for attributes. CREATE TYPE PointType AS OBJECT ( x NUMBER, y NUMBER ); / CREATE TYPE LineType AS OBJECT ( end1 PointType, end2 PointType, MEMBER FUNCTION length(scale IN NUMBER) RETURN NUMBER, PRAGMA RESTRICT_REFERENCES(length, WNDS)); / Methods are defined separately. Pragma is a directive to the compiler. WNDS means that this method does not modify database tables.

5 Advanced Databases (CM036): Lecture # 5 ( Object-Relational and Nested-Relational Databases) Methods on a UDOT Methods –Methods body is written in PL/SQL. CREATE TYPE BODY LineType AS MEMBER FUNCTION length(scale NUMBER) RETURN NUMBER IS BEGIN RETURN scale * SQRT((SELF.end1.x - SELF.end2.x) * (SELF.end1.x - SELF.end2.x) + (SELF.end1.y - SELF.end2.y) * (SELF.end1.y - SELF.end2.y) ); END; / –Methods can be invoked from PL/SQL or SQL queries (if free from side-effect defined by Pragma clause).

6 Advanced Databases (CM036): Lecture # 5 ( Object-Relational and Nested-Relational Databases) Object Tables Tables can be created that store collections of objects. CREATE TYPE Movie AS OBJECT ( Title varchar(15), Year number(4,0), Lenght number(3, 0)); / CREATE TABLE Movie_Tab OF Movie (PRIMARY KEY (Title)); –Such a table can be viewed as: A single column table in which each entry is a Movie object. A multi-column table in which each attribute of Movie is a column. –Objects that appear in object tables are called row objects. –Objects that appear as attributes of other objects or in table columns are called column objects.

7 Advanced Databases (CM036): Lecture # 5 ( Object-Relational and Nested-Relational Databases) Nested Tables A nested table is an unordered set of data elements that are all of the same data type. It has a single column of built-in type or UDOT. First define a type to be table of a some built-in type or UDOT. CREATE TYPE MovieTabTyp AS TABLE OF Movie; –Then define a column or attribute in another table or type of this new nested table type. CREATE TABLE Star ( Name varchar(15), …, Movies MovieTabTyp DEFAULT MovieTabTyp() ) NESTED TABLE Movies STORE AS Star_Movie; –Tuples in the Movies column are stored in a separate storage table called Star_Movie.

8 Advanced Databases (CM036): Lecture # 5 ( Object-Relational and Nested-Relational Databases) Nested Tables … Querying Nested Tables –This query returns values that may not be very useful for users. SELECT S.Name, S.Movies FROM Star S WHERE S.Name = 'Fisher' –We can Unnest the nested table to get some useful values. SELECT S.Name, M.Title, M.Year FROM Star S, TABLE (S.Movies) M WHERE S.Name = 'Fisher' –The above query returns the following values.

9 Advanced Databases (CM036): Lecture # 5 ( Object-Relational and Nested-Relational Databases) References To Objects Nested tables do not support sharing of objects and Relationships are value-based. References provide OID based 1:1 and 1:many relationships with object-relational features. CREATE TYPE PointTP AS OBJECT ( id integer, x NUMBER, y NUMBER ); / CREATE TABLE Points OF PointTP ( Primary Key (id) ); / CREATE TABLE Lines2 ( end1 REF PointTP, end2 REF PointTP) / –end1 and end2 attributes store references (pointers) to PointTP objects.

10 Advanced Databases (CM036): Lecture # 5 ( Object-Relational and Nested-Relational Databases) Collections of References Many:Many relationships can be represented by nested tables of references. References provide OID based 1:1, many:1, 1:many, many:many relationships with object-relational features. Create Type Movie_ref_typ as Object ( MovieRef REF Movie); / Create Type Movie_set_typ as Table of Movie_ref_typ; / CREATE TABLE Star ( Name varchar(15), …, Movies Movie_set_typ) NESTED TABLE Movies STORE AS Star_Movie; –Type Movie_ref_typ is an object with a single attribute that is a reference to an object of type Movie. –Now Movies is a nested table that contain references to Movie objects.

11 Advanced Databases (CM036): Lecture # 5 ( Object-Relational and Nested-Relational Databases) Populating Collections INSERT INTO TABLE ( SELECT S.Movies FROM Star S WHERE S.Name = 'Hamill') SELECT REF(m) FROM Movie_Tab m WHERE m.Title in ('Star Wars', 'Empire', 'War on Terror') / –The first select finds the nested table –The second select returns Reference to the movie objects that are then stored in the Movies nested table.

12 Advanced Databases (CM036): Lecture # 5 ( Object-Relational and Nested-Relational Databases) Querying Collections using DEREF

13 Advanced Databases (CM036): Lecture # 5 ( Object-Relational and Nested-Relational Databases) Querying Collections using Cursor

14 Advanced Databases (CM036): Lecture # 5 ( Object-Relational and Nested-Relational Databases) Querying Collections using Unnesting

15 Advanced Databases (CM036): Lecture # 5 ( Object-Relational and Nested-Relational Databases) Type Inheritance You can specialize the attributes or methods of a subtype in these ways: –Add new attributes that its parent supertype does not have. –Add entirely new methods that the parent does not have. –Change the implementation of some of the methods a subtype inherits from its parent so that the subtype's version executes different code from the parent's. FINAL and NOT FINAL Types and Methods –A type defined as NOT FINAL can be specialized. –By default all UDOTs are FINAL –By default all Methods are NOT FINAL –If you want to create a subtype of an UDOT defined as FINAL, you can do so using ALTER TYPE.

16 Advanced Databases (CM036): Lecture # 5 ( Object-Relational and Nested-Relational Databases) Type Inheritance: Examples A FINAL Type Definition CREATE TYPE Person_typ AS OBJECT ( NINUM CHAR(9), NAME VARCHAR2(30), ADDRESS VARCHAR2(100)) FINAL; Changing a type from FINAL to NOT FINAL ALTER TYPE Person_typ NOT FINAL; NOT FINAL type with a FINAL Method CREATE TYPE T AS OBJECT (..., MEMBER PROCEDURE Print(), FINAL MEMBER FUNCTION foo(x NUMBER)... ) NOT FINAL; Subtypes CREATE TYPE Student_typ UNDER Person_typ ( DEPTID NUMBER, MAJOR VARCHAR2(30)) NOT FINAL; CREATE TYPE PartTimeStudent_typ UNDER Student_typ ( NUMOFHOURS NUMBER(2));