KarczewskiDatenbanken 21 Object-Relational SQL Introduction: Object-Relational SQL (ORSQL) capabilities Objects and Tables OR-Create, -Insert, -Update,

Slides:



Advertisements
Similar presentations
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.
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.
Virtual training week 4 structured query language (SQL)
Structure Query Language (SQL) COMSATS INSTITUTE OF INFORMATION TECHNOLOGY, VEHARI.
1 DDL – subquery Sen Zhang. 2 Objectives What is a subquery? Learn how to create nested SQL queries Read sample scripts and book for different kinds of.
1 Table Alteration. 2 Altering Tables Table definition can be altered after its creation Adding columns Changing columns’ definition Dropping columns.
A Guide to SQL, Seventh Edition. Objectives Understand the concepts and terminology associated with relational databases Create and run SQL commands in.
Murali Mani SQL DDL and Oracle utilities. Murali Mani Datatypes in SQL INT (or) INTEGER FLOAT (or) REAL DECIMAL (n, m) CHAR (n) VARCHAR (n) DATE, TIME.
View Sen Zhang. Views are very common in business systems users view of data is simplified a form of security - user sees only the data he/she needs to.
30-Jun-15 SQL A Brief Introduction. SQL SQL is Structured Query Language Some people pronounce SQL as “sequel” Other people insist that only “ess-cue-ell”
Introduction to Structured Query Language (SQL)
A Guide to MySQL 3. 2 Objectives Start MySQL and learn how to use the MySQL Reference Manual Create a database Change (activate) a database Create tables.
CSC 2720 Building Web Applications Database and SQL.
Introduction to Oracle9i: SQL1 Views. Introduction to Oracle9i: SQL2 Chapter Objectives Create a view, using CREATE VIEW command or the CREATE OR REPLACE.
Inner join, self join and Outer join Sen Zhang. Joining data together is one of the most significant strengths of a relational database. A join is a query.
DAT702.  Standard Query Language  Ability to access and manipulate databases ◦ Retrieve data ◦ Insert, delete, update records ◦ Create and set permissions.
DATABASES AND SQL. Introduction Relation: Relation means table(data is arranged in rows and columns) Domain : A domain is a pool of values appearing in.
SQL Within PL / SQL Chapter 4. 2 SQL Within PL / SQL SQL Statements DML in PL / SQL Pseudocolums Transaction Control.
A Guide to SQL, Eighth Edition Chapter Three Creating Tables.
PL / SQL P rocedural L anguage / S tructured Q uery L anguage Chapter 7 in Lab Reference.
PL/SQLPL/SQL Oracle10g Developer: PL/SQL Programming Chapter 11 Introduction to Dynamic SQL and Object Technology.
Database Technical Session By: Prof. Adarsh Patel.
Constraints  Constraints are used to enforce rules at table level.  Constraints prevent the deletion of a table if there is dependencies.  The following.
CODD’s 12 RULES OF RELATIONAL DATABASE
Lecture 4 PL/SQL language. PL/SQL – procedural SQL Allows combining procedural and SQL code PL/SQL code is compiled, including SQL commands PL/SQL code.
1 Advanced Databases (CM036): Lecture # 5 ( Object-Relational and Nested-Relational Databases) Introduction to Object-Relational features of Oracle 9i.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
HSCI 709 SQL Data Definition Language. SQL Standard SQL-92 was developed by the INCITS Technical Committee H2 on Databases. SQL-92 was designed to be.
15/10/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
PHP MySQL Introduction. MySQL is the most popular open-source database system. What is MySQL? MySQL is a database. The data in MySQL is stored in database.
Database Fred Durao What is a database? A database is any organized collection of data. Some examples of databases you may encounter in.
Chapter 6 Additional Database Objects Oracle 10g: SQL.
1 Structured Query Language (SQL). 2 Contents SQL – I SQL – II SQL – III SQL – IV.
Oracle 11g DATABASE DEVELOPMENT LAB1. Introduction  Oracle 11g Database:-  Oracle 11g database is designed for some features, which helps to the organizations.
8-1 Copyright  Oracle Corporation, All rights reserved. Objects in Oracle8 1.Object Types - object-relational database 2.Large Objects (LOB) types.
IST 220 Introduction to Databases Course Wrap-up.
Topic 1: Introduction to SQL. SQL stands for Structured Query Language. SQL is a standard computer language for accessing and manipulating databases SQL.
A Guide to MySQL 3. 2 Introduction  Structured Query Language (SQL): Popular and widely used language for retrieving and manipulating database data Developed.
PL/SQL Block Structure DECLARE - Optional Variables, cursors, user-defined exceptions BEGIN - Mandatory SQL Statements PL/SQL Statements EXCEPTIONS - Optional.
SQL Fundamentals  SQL: Structured Query Language is a simple and powerful language used to create, access, and manipulate data and structure in the database.
SQL Basics. What is SQL? SQL stands for Structured Query Language. SQL lets you access and manipulate databases.
SQL Structured Query Language 1. Data Definition Language (DDL) is used to manage table and define data structure i.e. CREATE, ALTER, DROP Data Control.
What’s a database? Data stored in a structured format that lends itself to easy manipulation and recall.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
1 Ch. 1: Sharing Knowledge and Success  Oracle is an Object-Relational Database (ORDBMS).  RDBMS allows you to put the data in, keep the data, get it.
SQL LANGUAGE and Relational Data Model TUTORIAL Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha.
Object Relational Features
Variables and control statements in PL\SQL Chapter 10.
Chapter 13 Views Oracle 10g: SQL. Oracle 10g: SQL2 Objectives Create a view, using CREATE VIEW command or the CREATE OR REPLACE VIEW command Employ the.
Dynamic SQL. 2 home back first prev next last What Will I Learn? Recall the stages through which all SQL statements pass Describe the reasons for using.
Chapter 5 : Integrity And Security  Domain Constraints  Referential Integrity  Security  Triggers  Authorization  Authorization in SQL  Views 
CS34311 The Relational Model. cs34312 Why Relational Model? Currently the most widely used Vendors: Oracle, Microsoft, IBM Older models still used IBM’s.
Chapter 18 Object Database Management Systems. Outline Motivation for object database management Object-oriented principles Architectures for object database.
Relational Database Management System(RDBMS) Structured Query Language(SQL)
Distribution of Marks For Second Semester Internal Sessional Evaluation External Evaluation Assignment /Project QuizzesClass Attendance Mid-Term Test Total.
Kingdom of Saudi Arabia Ministry of Higher Education Al-Imam Muhammad Ibn Saud Islamic University College of Computer and Information Sciences Overview.
SQL Triggers, Functions & Stored Procedures Programming Operations.
Composite data types_ PL/SQL table. Composite data types PL/SQL provides three composite data types : TABLE, ROCORD, and VARRAY. Objects of type TABLE.
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.
Introduction to Database Programming with Python Gary Stewart
Relational Databases and SQL The relational model and the most common SQL commands.
3 A Guide to MySQL.
Quiz Questions Q.1 An entity set that does not have sufficient attributes to form a primary key is a (A) strong entity set. (B) weak entity set. (C) simple.
SQL 101.
Relational Database Design
Databases Continued 10/18/05.
DATABASE Purpose of database
SQL Views Presented by: Dr. Samir Tartir
Presentation transcript:

KarczewskiDatenbanken 21 Object-Relational SQL Introduction: Object-Relational SQL (ORSQL) capabilities Objects and Tables OR-Create, -Insert, -Update, -Select User Defined Functions

KarczewskiDatenbanken 22 ORSQL capabilities Definition of table will enlarged with user-defined types: Columns that look like multi-valued fields or have any internal structure (like a record) are not permitted (non 1NF) Example: eidenamepositiondependents dep_namedep_age e01Smith, JohnAgentMichael J.9 Susan R.7 e02Andrews, DavidSuperintendentDavid M. Jr.10 e03Jones, FranklinAgentAndrew K.11 Mark W.9 Louisa M.4

KarczewskiDatenbanken 23 ORSQL capabilities In OO-modeling there are methods defined to operate on the objects. The only possibility to operate on objects is to use this class-specific methods. There is no other posibiltiy to work on the data (encapsulation). In ORDBMS there exists the language ORSQL (like SQL in relational databases). This language allows to work on all defined multi-valued and structured tables. In addition you can define functions belonging to the defined OR tables (encapsulation).

KarczewskiDatenbanken 24 Objects and Tables An object type has attributes of various types, analogous to columns of a table. Example (Oracle): create type name_t as object-- „Create Object Type“ ( lnamevarchar(10),-- last name fnamevarchar(10),-- first name michar(1)-- middle initial ); /-- SQL*Plus

KarczewskiDatenbanken 25 Objects and Tables After making the SQL statement „create type“ you can use this new defined type like an attribute type. Example (Oracle): create table teachers-- „Create Table Scheme“ ( tidint,-- identifier tnamename_t,-- object type defined above roomint,-- room number primary key (tid) ); There is still no object exisiting from object type name_typ.

KarczewskiDatenbanken 26 Objects and Tables To insert a row into the table defined above you can use the insert statement like in relational SQL, extended with the possibility of using object types Example (Oracle): insert into teachers values ( 1234, name_t( ' Einstein ', ' Albert ', ' E ' ), 120 ); Object constructor

KarczewskiDatenbanken 27 Objects and Tables After the insert-statement used above the table content can be shown as follows: Example (Oracle): tid 1234 tname lnamefnamemi EinsteinAlbertE room 120

KarczewskiDatenbanken 28 Objects and Tables To select values of the object type we use a „dot“-notation: Example (Oracle): selectt.tid from teachers t wheret.room = 120; -- normal SQL-select selectt.tid, t.tname.fname, t.tname.lname fromteachers t wheret.room = 120; -- extended SQL selecttid, tname.fname, tname.lname fromteachers whereroom = 120; -- doesn´t work We must use the alias t for table teachers in the extended SQL.

KarczewskiDatenbanken 29 Objects and Tables It is possible to use the object type-definition within another object type-definition. Example: drop type person_t; -- drop a possibly existing type create type person_t as object ( ssnonumber(5), pnamename_t,-- must be defined first agenumber(5) ); person_typ is dependent on name_typ, that means you cannot drop name_typ before person_typ is dropped.

KarczewskiDatenbanken 210 Objects and Tables A table is called object table if its rows are of object type, that is, each of its rows consists of an object of that type. Example: create table people of person_t ( primary key(ssno) );

KarczewskiDatenbanken 211 Objects and Tables An example of a state of the table people: nameless top-level column holding the row object named columns (also known as top-level attributes) attributes within pname row 1 row 3 row 2 ssno pname pname.lname pname.fname pname.mi Sanchez Jose F Delaney Patrick X March Jacquelin E age people row objects column objects select * select value(p)

KarczewskiDatenbanken 212 select p.age from people p where p.ssno = (like relational statements) select p.pname from people p where p.age > 35 The columns will delivered in the form name_t(´Sanchez´, ´Jose´, ´F´) select * from people p where p.age > 35 delivers the top-level attributes (row objects) ssnopname(lname,fname,mi) age name_typ(´Delaney´,´Patrick´,´X´) name_typ(´Sanchez´,´Jose´,´F´) 30 Objects and Tables ( Select-statements )

KarczewskiDatenbanken 213 Objects and Tables ( Select-statements ) select value(p) from people p where age > 35 The nameless top-level column will be shown. Value(p) doesn´t mean VALUES within the insert-statement. Value(p)(ssno,pname(lname,fname,mi), age) person_t( ,name_t(´Delaney´,´Patrick´,´X´), 59) person_t( ,name_t(´Sanchez´,´Jose´,´F´), 30) Person_t is the object-constructor with which the table was defined, it is another result than in „select *“-queries. New functionality is given with this object constructor functionality.

KarczewskiDatenbanken 214 select value(p) from people p where p.pname = name_t(´Sanchez´,´Jose´,´F´) The object constructor „name_t(´Sanchez´,´Jose´,´F´)“ is allowed within the where-condition. Value(p)(ssno,pname(lname,fname,mi), age) person_t( ,name_t(´Sanchez´,´Jose´,´F´), 30) Objects and Tables ( Select-statements )

KarczewskiDatenbanken 215 select p.pname, p.age from people p where p.pname.fname like ‘Pat%‘= and p.age > 50; Nested dot notation is allowed. The first name starts with Pat and the age is over 50. pname(lname,fname,mi)age name_t(´Delaney´,´Patrick´,´X´)59 Nested dot notation can be used in any ORACLE select-statement to access an attribute of an object that is an attribute of an object... Objects and Tables ( Select-statements )

KarczewskiDatenbanken 216 Remark: You have to use the fully qualified name with an alias if you use an attribute accessing expression. select pname.fname from people This is not a top-level attribute -> This statement doesn´t work. select people.pname.fname from people Alias must be used because of attributes below the top level. -> This statement doesn´t work Objects and Tables ( Select-statements )

KarczewskiDatenbanken 217 create table scientists of name_t (primary key (lname)); Create a table with name scientists of object type name_t (defined above). insert into scientists select p.pname from people p; Insert with selection of all pnames of people. All rows of people table will be inserted. insert into scientists values (‘Einstein’, ‘Albert’, ‘E’); Insertion of one row into the table scientists with direct values. Objects and Tables ( create and insert )

KarczewskiDatenbanken 218 update scientists s set s = name_t(‘Eisenstein’, ‘Andrew’, ‘F’) where values(s) = name_t(‘Einstein’, ‘Albert’, ‘E’); Update of rows using object constructor name_t. insert into people values ( , name_t(’Einstein’, ’Albert’, ’E’), 100); Insertion of one row into the table scientist with direct values. insert into people values ( , null, null); insert into people values (ssno)( ); Equivalent statements to insert a row with null-values. Pname and age have to be optional attributes. A qualifier in the second example is not allowed. Objects and Tables ( insert )

KarczewskiDatenbanken 219 update people p set p.pname = name_t(‘Gould’, ‘Ben’, null) where ssno = ; Update of the row with null values. The middle initial is still null. update people p set p.pname.mi = ‘C’ where ssno = ; Update the middle initial of the row above. update people p set p = Person_t( , name_t(‘Gould’, ‘Glen’, ‘A’), 55) where ssno = ; Update of one person with row object constructor. The primary key ssno can also be updated. Objects and Tables ( update )

KarczewskiDatenbanken 220 User Defined Functions (UDF) can be used to bind functions to objects. The definition of UDF follows in two steps: 1.Definition of the function header 2.Definition of the function body The function header will be defined together with the attributes of the object type. The function body will be defined in a special command with a reference to the header. User Defined Functions

KarczewskiDatenbanken 221 Example (Persons and dependent Persons): create type name_t as object-- „Create Object Type“ ( lnamevarchar(30),-- last name michar(1),-- middle initial fnamevarchar(30)-- first name ); / create type person_t as object ( ssnoint, pnamename_t,-- must be defined first ageint ); / create type depPerson_t as table of person_t; / User Defined Functions

KarczewskiDatenbanken 222 Example (Function Header): create type Employee_t as object (ENRint, Personperson_t, depPersondepPerson_t, member function NumberOfDep return integer, member function BigBoss return varchar ); / The function headers will be defined after all attribute definitions. They include the key words “member function” and “return” with a data type. User Defined Functions

KarczewskiDatenbanken 223 Example (Function Body): create type body Employee_t as member function NumberOfDep return integer is begin return self.depPerson.count; end NumberOfDep; member function BigBoss return varchar is begin if self.depPerson.count > 2 then return 'Big Boss'; else return 'Boss'; end if; end BigBoss; end; / User Defined Functions The body of the functions get the same name as the above defined object type. The name and the return type of the function has to be written again. Within “begin” and “end” the function is defined. One return value is needed.

KarczewskiDatenbanken 224 Example (Table Definition): create table Employee of Employee_t ( primary key (ENR) ) nested table depPerson store as dep_tab; User Defined Functions The table definition makes the objects real! The primary key must be defined in the table definition. The “nested table” clause allows the use of tables within the table.

KarczewskiDatenbanken 225 Example (Insertion): insert into Employee values (1, person_t(11, name_t('Josef', 'R', 'Ewing'), 59), depPerson_T(person_t(33, name_t('Franz', 'X', 'Nonsense'), 33), person_t(44, name_t('Uschi', 'K', 'Glas'), 48), person_t(55, name_t('Mika', 'L', 'Most'), 52)) ); insert into Employee values (2, person_t(22, name_t('Karla', 'M', 'Hut'), 34), depPerson_T(person_t(66, name_t('Hans', 'L', 'Moser'), 72), person_t(77, name_t('Paul', 'A', 'Popp'), 41)) ); User Defined Functions Insertions will be made like in the examples before!

KarczewskiDatenbanken 226 Example (Selection): select ENR, E.NumberOfDep() from Employee E; ENR E.NUMBEROFDEP() The value of the result of the function (method) will be shown as an own column. The alias is mandatory! User Defined Functions Example (Selection): select ENR, E.BigBoss() from Employee E; ENR E.BIGBOSS() Big Boss 2 Boss The result can go over more than one line in PL/SQL.