EL Modelo Objeto-Relacional Por: ANGELICA URRUTIA GGR/2000.

Slides:



Advertisements
Similar presentations
MATEMÁTICAS I MEDIO PROGRAMA EMPRENDER PREUNIVERSITARIO ALUMNOS UC
Advertisements

SQL (I) Tema 3.
Structured Query Language (SQL)
Advanced Piloting Cruise Plot.
Advanced SQL Topics Edward Wu.
Copyright © 2003 Pearson Education, Inc. Slide 1 Computer Systems Organization & Architecture Chapters 8-12 John D. Carpinelli.
Chapter 1 The Study of Body Function Image PowerPoint
Copyright © 2011, Elsevier Inc. All rights reserved. Chapter 6 Author: Julia Richards and R. Scott Hawley.
Author: Julia Richards and R. Scott Hawley
1 Copyright © 2013 Elsevier Inc. All rights reserved. Appendix 01.
Properties Use, share, or modify this drill on mathematic properties. There is too much material for a single class, so you’ll have to select for your.
Refreshing Materialized Views
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
FACTORING ax2 + bx + c Think “unfoil” Work down, Show all steps.
Year 6 mental test 5 second questions
Year 6 mental test 10 second questions
Relational data objects 1 Lecture 6. Relational data objects 2 Answer to last lectures activity.
Introduction to Relational Database Systems 1 Lecture 4.
1 Term 2, 2004, Lecture 6, Views and SecurityMarian Ursu, Department of Computing, Goldsmiths College Views and Security 3.
Excel Functions. Part 1. Introduction 2 An Excel function is a formula or a procedure that is performed in the Visual Basic environment, outside the.
REVIEW: Arthropod ID. 1. Name the subphylum. 2. Name the subphylum. 3. Name the order.
1 Lecture 5: SQL Schema & Views. 2 Data Definition in SQL So far we have see the Data Manipulation Language, DML Next: Data Definition Language (DDL)
Part 3. Description of a function code 1. Part 3. Description of a function code 2 As an example we will write a function code to find the outside diameter.
PP Test Review Sections 6-1 to 6-6
ABC Technology Project
11 Copyright © Oracle Corporation, All rights reserved. Managing Tables.
9 Copyright © 2004, Oracle. All rights reserved. Using DDL Statements to Create and Manage Tables.
Oracle Object-Relational Model. - Structures : tables, views, indexes, etc. - Operations : actions that manipulate data stored in structures - Integrity.
Creating Tables, Setting Constraints, and Datatypes What is a constraint and why do we use it? What is a datatype? What does CHAR mean? Page 97 in Course.
R ELATIONAL M ODEL TO SQL Data Model. 22 C ONCEPTUAL D ESIGN : ER TO R ELATIONAL TO SQL How to represent Entity sets, Relationship sets, Attributes, Key.
Yong Choi School of Business CSU, Bakersfield
Microsoft Access.
Displaying Data from Multiple Tables
Creating Tables. 2 home back first prev next last What Will I Learn? List and provide an example of each of the number, character, and date data types.
Database System Concepts ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com ©Silberschatz, Korth and SudarshanDatabase.
1 Undirected Breadth First Search F A BCG DE H 2 F A BCG DE H Queue: A get Undiscovered Fringe Finished Active 0 distance from A visit(A)
2 |SharePoint Saturday New York City
VOORBLAD.
8 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Using Explicit Cursors.
Factor P 16 8(8-5ab) 4(d² + 4) 3rs(2r – s) 15cd(1 + 2cd) 8(4a² + 3b²)
Basel-ICU-Journal Challenge18/20/ Basel-ICU-Journal Challenge8/20/2014.
1..
© 2012 National Heart Foundation of Australia. Slide 2.
Lets play bingo!!. Calculate: MEAN Calculate: MEDIAN
Sets Sets © 2005 Richard A. Medeiros next Patterns.
LO: Count up to 100 objects by grouping them and counting in 5s 10s and 2s. Mrs Criddle: Westfield Middle School.
Understanding Generalist Practice, 5e, Kirst-Ashman/Hull
Fundamentals of Database Systems Fourth Edition El Masri & Navathe
Model and Relationships 6 M 1 M M M M M M M M M M M M M M M M
25 seconds left…...
Equal or Not. Equal or Not
Slippery Slope
Januar MDMDFSSMDMDFSSS
Week 1.
Analyzing Genes and Genomes
We will resume in: 25 Minutes.
©Brooks/Cole, 2001 Chapter 12 Derived Types-- Enumerated, Structure and Union.
Essential Cell Biology
Intracellular Compartments and Transport
PSSA Preparation.
Essential Cell Biology
Energy Generation in Mitochondria and Chlorplasts
Implementación en Oracle de SQL99
Object-Relational Oracle 11g Tutorial Νίκος Πελέκης Εργαστήριο Πληροφοριακών Συστημάτων, Τμήμα Πληροφορικής, Πανεπιστήμιο Πειραιώς
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Object-Relational Database Programming.
Presentation transcript:

EL Modelo Objeto-Relacional Por: ANGELICA URRUTIA GGR/2000

Contenido Introducción El modelo Objeto-Relacional Creación de tipos de datos Creación de tablas Manipulación de objetos GGR/2000

El Modelo Objeto-Relacional Modelo de Objetos sobre el modelo relacional –Object types (Name, attributes, Methods) Object_Variable.Method() UCM GGR/2000

El Modelo Objeto-Relacional GGR/2000 Purchase Order PONo OrderDate ShipDate getPONo() sumLineItems()

El Modelo Objeto-Relacional GGR/2000 purchase_order( , person ("John Smith"," "), NULL ) Constructor

El Modelo Objeto-Relacional GGR/2000 CREATE TABLE person_table OF person; Object Table: Es un tipo especial de tabla en la cual cada fila representa un objeto INSERT INTO person_table VALUES ( "John Smith"," " ); SELECT VALUE(p) FROM person_table p WHERE p.name = "John Smith";

El Modelo Objeto-Relacional GGR/2000 Row Objects Columns objects

El Modelo Objeto-Relacional GGR/2000 REF Datatype Puntero Lógico a un Row Objects CREATE TYPE person AS OBJECT ( name VARCHAR2(30), manager REF person ); DECLARE OrderRef REF to Purchase_order; SELECT REF(po) INTO OrderRef FROM purchase_order_table po WHERE po.id = ;

El Modelo Objeto-Relacional GGR/2000 Collections/VARRAYs CREATE TYPE prices AS VARRAY(10) OF NUMBER(12,2); Conjunto Ordenado de elementos Todos Los elementos son del mismo tipo Cada elemento tiene un índice

El Modelo Objeto-Relacional GGR/2000 Collections/Nested Table CREATE TYPE lineitem_table AS TABLE OF lineitem ; Conjunto no Ordenado de elementos Todos Los elementos son del mismo tipo Tiene una sola columna (built-in, Object Type) NESTED TABLE lineitems STORE AS lineitems_table;

El Modelo Objeto-Relacional GGR/2000 Herencia SUBTYPE Empleado IS Persona[(constraint)] [NOT NULL];

El Modelo Objeto-Relacional GGR/2000 CREATE TYPE person AS OBJECT (name VARCHAR2(30),phone VARCHAR2(20) ); CREATE TABLE contacts (contact person, date DATE ); INSERT INTO contacts VALUES (person (NULL, NULL), ’24 Jun 1997’); INSERT INTO contacts VALUES (NULL,’24 Jun 1997’ ); Valores Nulos

El Modelo Objeto-Relacional GGR/2000 Valores por defecto para objetos y coleciones CREATE TYPE person AS OBJECT ( id NUMBER, name VARCHAR2(30), address VARCHAR2(30) ); CREATE TYPE people AS TABLE OF person; people ( person(1, ’John Smith’, ’5 Cherry Lane’), person(2, ’Diane Smith’, NULL) ) CREATE TABLE department ( d_no CHAR(5) PRIMARY KEY, d_name CHAR(20), d_mgr person DEFAULT person(1,’John Doe’,NULL), d_emps people DEFAULT people() ) NESTED TABLE d_emps STORE AS d_emps_tab;

El Modelo Objeto-Relacional GGR/2000 Constraint para Object Tables CREATE TYPE location (building_no NUMBER,city VARCHAR2(40) ); CREATE TYPE person (ssno NUMBER,name VARCHAR2(100), address VARCHAR2(100),office location ); CREATE TABLE person_extent OF person (ssno PRIMARY KEY ); CREATE TABLE department ( deptno CHAR(5) PRIMARY KEY, dept_name CHAR(20),dept_mgr person, dept_loc location, CONSTRAINT dept_loc_cons1 UNIQUE (dept_loc.building_no, dept_loc.city), CONSTRAINT dept_loc_cons2 CHECK (dept_loc.city IS NOT NULL) );

El Modelo Objeto-Relacional GGR/2000 Indices para Tablas Objetos y Tablas anidadas CREATE TABLE department deptno CHAR(5) PRIMARY KEY, dept_name CHAR(20), dept_addr address ); CREATE INDEX i_dept_addr1 ON department (dept_addr.city);

El Modelo Objeto-Relacional GGR/2000 Triggers para Tablas Objetos CREATE TABLE movement (ssno NUMBER,old_office, location, new_office location ); CREATE TRIGGER trig1 BEFORE UPDATE OF office ON person_extent FOR EACH ROW WHEN new.office.city = ’REDWOOD SHORES’ BEGIN IF :new.office.building_no = 600 THEN INSERT INTO movement (ssno, old_office, new_office) VALUES (:old.ssno, :old.office, :new.office); END IF; END;

El Modelo Objeto-Relacional GGR/2000 Example 1 - Tipo definido por el usuario CREATE OR REPLACE TYPE Address AS OBJECT ( Street VARCHAR2(80), City VARCHAR2(80), State CHAR(2), Zip VARCHAR2(10) ); Example 2 - Tabla Anidada CREATE OR REPLACE TYPE AddressList AS TABLE OF Address;

El Modelo Objeto-Relacional GGR/2000 Example 3 - User-Defined VARRAY Type CREATE OR REPLACE TYPE PhoneList AS VARRAY(10) OF VARCHAR2(12); Example 4 - User-Defined Object Type with Embedded Object CREATE OR REPLACE TYPE Person AS OBJECT ( FirstName VARCHAR2(10), LastName VARCHAR2(10), CurAddr Address );

El Modelo Objeto-Relacional GGR/2000 Example 5 - User-Defined Object Type with REF CREATE OR REPLACE TYPE Person; // Tipo Incompleto// CREATE OR REPLACE TYPE Person AS OBJECT ( FirstName VARCHAR2(10), LastName VARCHAR2(10), CurAddr Address, Mom REF Person, Dad REF Person, PrevAddrs AddressList, PhoneNums PhoneList );

El Modelo Objeto-Relacional GGR/2000 Example 7 - User-Defined Object Type with Methods CREATE OR REPLACE TYPE Person; CREATE OR REPLACE TYPE Person AS OBJECT ( FirstName VARCHAR2(10), LastName VARCHAR2(10), CurAddr Address, Mom REF Person, Dad REF Person, PrevAddrs AddressList, PhoneNums PhoneList, MEMBER FUNCTION FullName RETURN VARCHAR2, MEMBER PROCEDURE MoveTo(newAddr IN Address), PRAGMA RESTRICT_REFERENCES(FullName, RNDS, WNDS) );

El Modelo Objeto-Relacional GGR/2000 Example 7 (continuación) CREATE OR REPLACE TYPE BODY Person AS MEMBER FUNCTION FullName RETURN VARCHAR2 IS BEGIN RETURN (SELF.FirstName || ' ' || SELF.LastName); END FullName;

El Modelo Objeto-Relacional GGR/2000 Example 8 - Creating an Object Table CREATE TABLE People OF Person NESTED TABLE PrevAddrs STORE AS PrevAddrTab; Example 9 - Creating a Table with an Object Column CREATE TABLE Corporation ( CorpName VARCHAR2(80), CorpAddr Address, CorpCEO REF Person SCOPE IS People );

El Modelo Objeto-Relacional GGR/2000 Example 10 - Creating an Object Table with Constraints and Defaults CREATE TABLE People OF Person ( FirstName NOT NULL, LastName NOT NULL, CurAddr DEFAULT Address('500 Oracle Parkway', 'Redwood Shores', 'CA', '94065') ) NESTED TABLE PrevAddrs STORE AS PrevAddrTab;

El Modelo Objeto-Relacional GGR/2000 Example 11 - Returning a Nested Table as a Locator CREATE TABLE People OF Person ( FirstName NOT NULL, LastName NOT NULL, CurAddr DEFAULT Address('500 Oracle Parkway', 'Redwood Shores', 'CA', '94065') ) NESTED TABLE PrevAddrs STORE AS PrevAddrTab RETURN AS LOCATOR;

El Modelo Objeto-Relacional GGR/2000 Example 12 - Populating the People Table INSERT INTO People VALUES ( Person('Mr.', 'Ellison', Address('1 First Street', 'Orlando', 'FL', '34812'), NULL, NULL, AddressList(Address('2 Second Street', 'Orlando', 'FL', '34812'), Address('3 Third Street', 'Orlando', 'FL', '34812')), PhoneList(' ', ' ')) );

El Modelo Objeto-Relacional GGR/2000 Example 12 - Populating the People Table (cont..) INSERT INTO People VALUES ( Person('Larry', 'Ellison', Address('1 First Street', 'Orlando', 'FL', '34812'), (SELECT REF(p) FROM People p WHERE p.FirstName = 'Mrs.' AND p.LastName = 'Ellison'), (SELECT REF(p) FROM People p WHERE p.FirstName = 'Mr.' AND p.LastName = 'Ellison'), AddressList(Address('2 Second Street', 'Orlando', 'FL', '34812'), Address('3 Third Street', 'Orlando', 'FL', '34812')), PhoneList(' ', ' ')) );

El Modelo Objeto-Relacional GGR/2000 Example 13 - Populating the Corporation Table INSERT INTO Corporation VALUES ( 'Oracle Corporation', Address('500 Oracle Parkway', 'Redwood Shores', 'CA', '94065'), (SELECT REF(p) FROM People p WHERE p.FirstName = 'Larry' AND p.LastName = 'Ellison') );

El Modelo Objeto-Relacional GGR/2000 Example 14 - Selecting an Embedded Object SELECT c.CorpAddr FROM Corporation c WHERE c.CorpName = 'Oracle Corporation'; Example 15 - Selecting an Attribute of an Embedded Object SELECT c.CorpAddr.Street FROM Corporation c WHERE c.CorpName = 'Oracle Corporation';

El Modelo Objeto-Relacional GGR/2000 Example 16 - Selecting an Object from an Object Table SELECT VALUE(p) FROM People p WHERE p.LastName = 'Ellison'; Example 17 - Selecting an Object Reference from an Object Table SELECT REF(p) FROM People p WHERE p.LastName = 'Ellison';

El Modelo Objeto-Relacional GGR/2000 Example 18 - Selecting a Nested Table Column from an Object Table SELECT p.PrevAddrs FROM People p WHERE p.LastName = 'Ellison'; Example 19 - Selecting a VARRAY Column from an Object Table SELECT p.PhoneNums FROM People p WHERE p.LastName = 'Ellison';

El Modelo Objeto-Relacional GGR/2000 Example 20 - Selecting Objects from a Nested Table SELECT VALUE(a) FROM TABLE(SELECT p.PrevAddrs FROM People p WHERE p.FirstName = 'Larry' AND p.LastName = 'Ellison') a;

El Modelo Objeto-Relacional GGR/2000 Example 21 - Collection Unnesting using the TABLE operator SELECT p.FirstName, p.LastName, a.* FROM People p, TABLE(p.PrevAddrs) a WHERE p.LastName = 'Ellison'; p.FirstName p.LastName a.Street a.City a.State a.Zip Mr. Ellison 2 Second Street Orlando FL Mr. Ellison 3 Third Street Orlando FL Mrs. Ellison 2 Second Street Orlando FL Mrs. Ellison 3 Third Street Orlando FL Larry Ellison 2 Second Street Orlando FL Larry Ellison 3 Third Street Orlando FL 34812

El Modelo Objeto-Relacional GGR/2000 Example 22 - Collection Unnesting using an Outer Join SELECT p.FirstName, p.LastName, a.* FROM People p, TABLE(p.PrevAddrs) (+) a WHERE p.Lastname = 'Ellison'; Example 23 - Collection Unnesting with a VARRAY SELECT p.FirstName, p.LastName, ph.* FROM People p, TABLE(p.PhoneNums) ph WHERE p.LastName = 'Ellison';

El Modelo Objeto-Relacional GGR/2000 Example 24 - Selecting Data from a Referenced Object SELECT p.Mom.FirstName FROM People p WHERE p.FirstName = 'Larry' and p.LastName = 'Ellison'; Example 25 - Selecting a Member Function on an Object Table SELECT p.FullName() FROM People p WHERE p.LastName = 'Ellison';

El Modelo Objeto-Relacional GGR/2000 Example 26 - Selecting a Member Function on a Referenced Object SELECT c.CorpCEO.FullName() FROM Corporation c WHERE c.CorpName = 'Oracle Corporation';

El Modelo Objeto-Relacional GGR/2000 Example 27 - Querying a Nested Table Using a Nested Table Locator DECLARE theCEO Person; theAddr Address; BEGIN SELECT VALUE(p) INTO theCEO FROM People p WHERE p.FirstName = 'Larry' AND p.LastName = 'Ellison'; IF (UTL_COLL.IS_LOCATOR(theCEO.PrevAddrs)) THEN SELECT VALUE(a) INTO theAddr FROM TABLE(CAST(theCEO.PrevAddrs AS AddressList)) a WHERE a.Street = '2 Second Street'; ELSE FOR ndx IN 1..theCEO.PrevAddrs.COUNT LOOP IF (theCEO.PrevAddrs(ndx) = '2 Second Street') THEN theAddr := theCEO.PrevAddrs(ndx); END IF; END LOOP; END IF; END;

El Modelo Objeto-Relacional GGR/2000 Example 28 - Invoking a Member Procedure on an Object Type DECLARE theCEO Person; newAddr Address := Address('500 Oracle Parkway', 'Redwood Shores', 'CA', '94065'); BEGIN -- retrieve Person object from the database SELECT VALUE(p) INTO theCEO FROM People p WHERE p.FirstName = 'Larry' AND p.LastName = 'Ellison'; -- change the address of the transient Person object theCEO.moveTo(newAddr); -- update the corresponding Person object in the database UPDATE People p SET p = theCEO WHERE p.FirstName = 'Larry' AND p.LastName = 'Ellison'; END;

El Modelo Objeto-Relacional GGR/2000 Example 29 - Inserting into a Nested Table Using SQL INSERT INTO TABLE(SELECT p.PrevAddrs FROM People p WHERE p.FirstName = 'Larry' AND p.LastName = 'Ellison') VALUES ( Address('123 First Avenue', 'San Francisco', 'CA', '90909') );

El Modelo Objeto-Relacional GGR/2000 Example 30 - Update a Nested Table Using SQL UPDATE TABLE(SELECT p.PrevAddrs FROM People p WHERE p.FirstName = 'Larry' AND p.LastName = 'Ellison') pa SET pa.Zip = '90910' WHERE pa.City = 'San Francisco' AND pa.State = 'CA';

El Modelo Objeto-Relacional GGR/2000 Example 31 - Querying Referenced Objects using DEREF SELECT DEREF(c.CorpCEO) FROM Corporation c WHERE c.CorpName = 'Oracle Corporation';

El Modelo Objeto-Relacional GGR/2000 Example 30 - Update a Nested Table Using SQL UPDATE TABLE(SELECT p.PrevAddrs FROM People p WHERE p.FirstName = 'Larry' AND p.LastName = 'Ellison') pa SET pa.Zip = '90910' WHERE pa.City = 'San Francisco' AND pa.State = 'CA';

Subtypos GGR/2000 Example 31 – CREATE TYPE Using SQL CREATE TYPE direccion AS OBJECT (n-rut, calle varchar (10)) CREATE TYPE persona AS OBJECT (rut int, dir direccion)

Subtypos GGR/2000 Example 32 – CREATE TABLE Using SQL (objeto fila) CREATE TABLE person OF persona INSERT INTO person VALUES (persona ( ), direccion (1 sur 1350));

Subtypos GGR/2000 Example 32 – CREATE TABLE Using SQL (objeto columna) CREATE TABLE person1 OF (persona, sal INT (6)) CREATE TABLE person1 OF ( per persona, sal INT (6) INSERT INTO person1 VALUES (persona ( ), direccion (1 sur 1350), );