Object-Relational Features

Slides:



Advertisements
Similar presentations
Advanced SQL (part 1) CS263 Lecture 7.
Advertisements

Oracle Object-Relational Model. - Structures : tables, views, indexes, etc. - Operations : actions that manipulate data stored in structures - Integrity.
9 Creating and Managing Tables. Objectives After completing this lesson, you should be able to do the following: Describe the main database objects Create.
Data Definition Language (DDL)
Professor: Dr. Shu-Ching Chen TA: Hsin-Yu Ha.  Objects  Varray  Nested Table  Transaction Control Language(TCL)
Oracle 10g Database Administrator: Implementation and Administration Chapter 8 Advanced Table Management.
Oracle Objects Object Oriented Database Approach.
Introduction to PL/SQL Lecture 0 – Self Study Akhtar Ali.
Objectives Why PL-SQL ? Language features
ORACLE ONLINE TRAINING Contact our Support Team : SOFTNSOL India: Skype id : softnsoltrainings id:
1 © 2008 Julian Dyke LOB Internals Julian Dyke Independent Consultant juliandyke.com Web Version - December 2008.
CHAPTER 11 Large Objects. Need for Large Objects Data type to store objects that contain large amount of text, log, image, video, or audio data. Most.
CPS120: Introduction to Computer Science Information Systems: Database Management Nell Dale John Lewis.
Chapter Oracle Server An Oracle Server consists of an Oracle database (stored data, control and log files.) The Server will support SQL to define.
PL/SQLPL/SQL Oracle10g Developer: PL/SQL Programming Chapter 11 Introduction to Dynamic SQL and Object Technology.
Database Technical Session By: Prof. Adarsh Patel.
1 Advanced Databases (CM036): Lecture # 5 ( Object-Relational and Nested-Relational Databases) Introduction to Object-Relational features of Oracle 9i.
INTRODUCTION TO PL/SQL. Class Agenda Introduction Introduction to PL/SQL Declaring PL/SQL Variable Creating the Executable Section Interacting with the.
Sizing Basics  Why Size?  When to size  Sizing issues:  Bits and Bytes  Blocks (aka pages) of Data  Different Data types  Row Size  Table Sizing.
Overview · What is PL/SQL · Advantages of PL/SQL · Basic Structure of a PL/SQL Block · Procedure · Function · Anonymous Block · Types of Block · Declaring.
1 Creating and Modifying Database Objects. 2 An Oracle database consists of multiple user accounts Each user account owns database objects Tables Views.
1 Oracle 8. 2 New features 3 Oracle 8 New features  Abstract data types New features  Abstract data types.
PL / SQL By Mohammed Baihan. What is PL/SQL? PL/SQL stands for Procedural Language extension of SQL. PL/SQL is a combination of SQL along with the procedural.
8-1 Copyright  Oracle Corporation, All rights reserved. Objects in Oracle8 1.Object Types - object-relational database 2.Large Objects (LOB) types.
Database structure and space Management. Database Structure An ORACLE database has both a physical and logical structure. By separating physical and logical.
Oracle 8i PL/SQL Collections. Collections A Collection is a group of elements of the same kind There are three types of Collections that you can use in.
Oracle 8i Building PL/SQL Blocks. Creating PL/SQL Blocks CURSORS PROCEDURES FUNCTIONS PACKAGES TRIGGERS CURSORS PROCEDURES FUNCTIONS PACKAGES TRIGGERS.
Chapter 15 Introduction to PL/SQL. Chapter Objectives  Explain the benefits of using PL/SQL blocks versus several SQL statements  Identify the sections.
Database Application Development using PL/SQL Programming.
SQL for the Non - Technician Jeffrey Walsh AnswerThink Consulting Group, Inc.
SQL Fundamentals  SQL: Structured Query Language is a simple and powerful language used to create, access, and manipulate data and structure in the database.
Database structure and space Management. Segments The level of logical database storage above an extent is called a segment. A segment is a set of extents.
School of Computing and Management Sciences © Sheffield Hallam University SQL is non-procedural –designed to be relatively approachable to non- programmers.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
Week 4 Lecture 2 Advanced Table Management. Learning Objectives  Create tables with large object (LOB) columns and tables that are index-organized 
Visual Programing SQL Overview Section 1.
SQL Jan 20,2014. DBMS Stores data as records, tables etc. Accepts data and stores that data for later use Uses query languages for searching, sorting,
9 Copyright © Oracle Corporation, All rights reserved. Creating and Managing Tables.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide Introduction Object Oriented (OO) Data Models since mid-90’s Reasons for creation of.
9 Copyright © 2004, Oracle. All rights reserved. Manipulating Large Objects.
© D. Wong Security and User Authorization in SQL 8.7 pp. 410  Authorization ID = user name  Special authorization ID: PUBLIC  Privileges for:
Oracle & SQL. Oracle Data Types Character Data Types: Char(2) Varchar (20) Clob: large character string as long as 4GB Bolb and bfile: large amount of.
SLIDE 1IS 257 – Fall 2014 NoSQL Databases University of California, Berkeley School of Information IS 257: Database Management.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
Oracle 10g Database Administrator: Implementation and Administration Chapter 10 Basic Data Management.
Dale Roberts 1 Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
1 Part IV: Object-Relational Databases  Ch. 30: Types, Object Views, Methods  Ch. 31: Nested Tables and Varying Arrays  Ch. 32: Large Objects  Ch.
8 Copyright © 2005, Oracle. All rights reserved. Managing Schema Objects.
1 Section 1 - Introduction to SQL u SQL is an abbreviation for Structured Query Language. u It is generally pronounced “Sequel” u SQL is a unified language.
1 Chapters 19 and 20  Ch. 19: By What Authority? Users Roles Grant and revoke Synonyms  Ch. 20: Changing the Oracle Surroundings Indexes Clusters Sequences.
CIT 214 Introduction to Database Management
Fundamentals of DBMS Notes-1.
Introduction To Oracle
Pl/SQL LANGUAGE MULITPLE CHOICE QUESTION SET-3
Module 11: File Structure
Database structure and space Management
Collection in PL/SQL.
Object-Relational DBMSs
Chapter 4 Relational Databases
DATABASE SQL= Structure Query Language مبادئ قواعد بيانات
Databases and Information Management
DATABASE MANAGEMENT SYSTEM
Xerion Pharmaceuticals AG
SQL data definition using Oracle
Chapter 10 Oracle9i Developer: PL/SQL Programming
Databases and Information Management
The Physical Design Stage of SDLC (figures 2.4, 2.5 revisited)
Managing Tables.
PL/SQL Declaring Variables.
Object – relational database
Presentation transcript:

Object-Relational Features Department of Computer and Information Science, School of Science, IUPUI Object-Relational Features Dale Roberts, Lecturer Computer Science, IUPUI E-mail: droberts@cs.iupui.edu

Object-Relational Databases Types, Object Views, Methods Nested Tables and Varying Arrays Large Objects Advanced OO Concepts 2

Types Abstract datatypes groups related columns/data . create type ADDRESS_TY as object ( Street VARCHAR2(50), City VARCHAR2(25), State CHAR(2), Zip NUMBER); Abstract datatypes can be nested . security – must have EXECUTE privilege to use a type. set describe depth – see attributes within an object. 3

Types: indexing, selecting, manipulating Create type PERSON_TY ( Name VARCHAR2(25), Address ADDRESS_TY); Create table CUSTOMER ( Cust_Id NUMBER, Person PERSON_TY ); Select: select c.Name, c.Person.Address.City from CUSTOMER c where c.Person.Address.City like ‘I%’; Indexing: create index IDX_CUST on CUSTOMER (Person.Address.City); Insert: insert into CUSTOMER values (1, PERSON_TY(‘xxxx’, ADDRESS_TY(‘aaaa’, ‘bbb’, ccc’))); 4

Object Views Inserting into original table: create table CUSTOMER (Cust_id NUMBER PRIMARY KEY, Name VARCHAR2(25), Street VARCHAR2(50), City VARCHAR2(25), State CHAR(2), Zip NUMBER); create type ADDRESS_TY as object ( Street VARCHAR2(50), City VARCHAR2(25), State CHAR(2), Zip NUMBER); create type PERSON_TY ( Name VARCHAR2(25), Address ADDRESS_TY); create or replace view CUSTOMER_OV (Cust_id, person) as select Cust_id, PERSON_TY (Name, ADDRESS_TY(street, city, state, zip)) from CUSTOMER; Inserting into original table: insert into CUSTOMER values ( 123, ‘name’, ‘Street’, ‘City’, ‘ST’, 99999 ); Inserting into object view: insert into CUSTOMER_OV values ( 123, PERSON_TY(‘name’, ADDRESS_TY( ‘Street’, ‘City’, ‘ST’, 99999 ))); 5

INSTEAD OF Triggers Views usually cannot use standard table-based PL/SQL Triggers, but they can use INSTEAD OF triggers. Works with either normal views or object views. create trigger AUTHOR_PUBLISHER_UPDATE instead of UPDATE on AUTHOR_PUBLISHER for each row begin … end; 6

Methods Methods allow types to have “behavior”. Methods are declared inside CREATE TYPE, they are defined with CREATE TYPE BODY. create type PERSON_TY ( Name VARCHAR2(25), Address ADDRESS_TY, Birthday DATE, member function AGE (BirthDate IN DATE) return NUMBER); create or replace type body PERSON_TY as member function AGE (Birthdate DATE) return NUMBER is begin return ROUND(sysdate – Birthdate); end; end; 7

Collections: Varying Arrays Definition – a varying array is a set of objects, each of same type, seen as a column within a table. The size is limited when created. Creating a Varying Array Create type TOOL_TY as object (…); Create type TOOLS_VA as varray(5) of VARCHAR2(25); Create table TOOL_BORROWER (…, Tools TOOLS_VA); Describing – requires queries on data dictionary to show varray structure. Selecting – requires PL/SQL, see p. 571-572 Inserting – insert into TOOL_BORROWER values (‘name’, TOOLS_VA(‘tool1’, ‘tool2’, ‘tool3’)); Storage – stored in-line, ie. within table data segment. 8

Collections: Nested Tables Definition – a nested table is a table within a table. Their size is not limited as with varying arrays. Creating a Nested Table Create type TOOL_TY as object (…); Create type TOOLS_NT as table of TOOL_TY; Create table TOOL_BORROWER (…, nested table Tools TOOLS_NT); Describing – set describe depth will allow the describe command to show nested tables. Selecting – requires the TABLE() function (previous to 9i use THE() function). This “flatten’s” or de-normalizes the nested table’s relationship. Select BreederName, N.Name, N.birthdate from BREEDER, TABLE(breeder.Animals) N Inserting – insert into TABLE(select Animals from BREEDER where Breedername = ‘x’) values (ANIMAL_TY (‘x’,’y’,’z’)); Storage – Nested tables can be stored in or out-of-line. Recommend they be stored out-of-line with a storage clause to improves query performance. 9

Large Object Datatypes BLOB – binary field up to 4Gb. CLOB – character field up to 4Gb. NCLOB – CLOB that supports MBCS (multi-byte character set). BFILE – read-only binary data stored in a file outside of the database. 10

LOB Storage, Initialization LOB Storage – BLOB and (N)CLOB columns are stored out-of-line. They require the CREATE TABLE statement include a LOB STORAGE clause to tell where the LOB segment is stored. BFILE columns are by their nature stored out-of-line. LOBs use at least 1 entire data block per row in the LOB segment. Normal DATA segments store multiple rows per block (up to 100% -PCTFREE). Initializing LOBs – use EMPTY_BLOB or EMPTY_CLOB instead of NULL to initialize a LOB. NULL will create a LOB with no data. EMPTY_BLOB/CLOB will create an empty “LOB locater” (pointer) without allocating the empty block. 11

DBMS_LOB LOB data is manipulated with the DBMS_LOB package. For all LOBs: APPEND COMPARE COPY ERASE GETCHUNKSIZE GETLENGTH INSTR ISOPEN OPEN READ SUBSTR TRIM WRITE WRITEAPPEND BFILE specific functions: FILEOPEN FILECLOSE FILECLOSEALL FILEEXISTS FILEGETNAME FILEISOPEN LOADFROM FILE Temporary LOB functions: CREATETEMPORARY FREETEMPORARY ISTEMPORARY 12

BFILE Read-only binary data stored in a file outside of the database. CREATE DIRECTORY PROPOSAL_DIR AS ‘C:\My Documents’; Insert into thetable ( col1, bfilecol ) values ( ‘value1’, BFILENAME(‘proposal_dir’, ‘myfile.doc’); Deleting LOBs – internal LOBs when deleted have both their data and LOB locater deleted. Deleting a BFILE only deletes the locater, the file is read only and thus not changed. 13

row objects vs. column objects 14

REF, DEREF, VALUE REF DEREF VALUE 15

Acknowledgements Loney, Oracle Database 10g The Complete Reference 1/18/2019