Oracle’s take on joins Where it differs from ANSI standard.

Slides:



Advertisements
Similar presentations
Let’s try Oracle. Accessing Oracle The Oracle system, like the SQL Server system, is client / server. For SQL Server, –the client is the Query Analyser.
Advertisements

Building a database. Implementation of desirable features Integrity –A field’s validation can be declared when the field is declared. If this validation.
10 Copyright © 2004, Oracle. All rights reserved. Creating Other Schema Objects.
Introduction to Structured Query Language (SQL)
SQL components In Oracle. SQL in Oracle SQL is made up of 4 components: –DDL Data Definition Language CREATE, ALTER, DROP, TRUNCATE. Creates / Alters.
Some relationship types Using the Builder2 schema.
PL/SQL Continued. So far… Anonymous blocks Procedures Have you tried… –Downloading and running the dispcust.sql sample from your web page? –Writing your.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 8 Advanced SQL.
Sample queries Practice in using Oracle SQL (1 of 2)
1 Databases Semester 2 Week 1 Lab 2 The Delete, grant, revoke and Select Statements.
Chapter 3: Using SQL Queries to Insert, Update, Delete, and View Data
A Guide to Oracle9i1 Advanced SQL And PL/SQL Topics Chapter 9.
DT211 Stage 2 Databases Lab 1. Get to know SQL Server SQL server has 2 parts: –A client, running on your machine, in the lab. You access the database.
Copyright س Oracle Corporation, All rights reserved. 13 Other Database Objects.
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.
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.
1 PL/SQL programming Procedures and Cursors Lecture 1 Akhtar Ali.
SQL Query Extras MIS 433. Rerunning the last Query n Type the forward slash “/” to rerun the last query that was entered.
ORACLE ONLINE TRAINING Contact our Support Team : SOFTNSOL India: Skype id : softnsoltrainings id:
Structured Query Language (SQL) A2 Teacher Up skilling LECTURE 2.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
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.
Chapter 7 Advanced SQL Database Systems: Design, Implementation, and Management, Sixth Edition, Rob and Coronel.
13 Other Database Objects Important Legal Notice:  Materials on this lecture are from a book titled “Oracle Education” by Kochhar, Gravina, and Nathan.
Programming using C# Joins SQL Injection Stored Procedures
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.
Copyright © 2004, Oracle. All rights reserved. Lecture 3: Creating Other Schema Objects Lecture 3: Creating Other Schema Objects ORACLE.
12 Copyright © Oracle Corporation, All rights reserved. Other Database Objects.
Other database objects (Sequence). What Is a Sequence? A sequence: Automatically generates sequential numbers Is a sharable object Is typically used to.
11 Copyright © 2007, Oracle. All rights reserved. Creating Other Schema Objects.
1 All Powder Board and Ski Oracle 9i Workbook Chapter 7: Integrity and Transactions Jerry Post Copyright © 2003.
Chapter 5 Sequences.
Structure Query Language SQL. Database Terminology Employee ID 3 3 Last name Small First name Tony 5 5 Smith James
IMS 4212: Intro to SQL 1 Dr. Lawrence West, Management Dept., University of Central Florida Introduction to SQL—Topics Introduction to.
Database Programming Sections 11 & 12 – Creating, and Managing Views, Sequences, Indexes, and Synonymns.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
ITBIS373 Database Development Lecture 3a - Chapter 3: Using SQL Queries to Insert, Update, Delete, and View Data.
A Guide to MySQL 3. 2 Introduction  Structured Query Language (SQL): Popular and widely used language for retrieving and manipulating database data Developed.
8 1 Chapter 8 Advanced SQL Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
1 PL\SQL Dev Templates. 2 TEMPLATE DEFINITION Whenever you create a new program unit, its initial contents are based upon a template which contains pre-defined.
Stored Procedures. Definition a stored procedure is a set of Structured Query Language (SQL) statements with an assigned name that's stored in the database.
Database Programming Sections 11 & 12 –Sequences, Indexes, and Synonymns.
5. Simple SQL using Oracle1 Simple SQL using Oracle 5. Working with Tables: Data management and Retrieval 6. Working with Tables: Functions and Grouping.
Chapter 9: Advanced SQL and PL/SQL Guide to Oracle 10g.
SQL ACTION QUERIES AND TRANSACTION CONTROL CS 260 Database Systems.
Views, Algebra Temporary Tables. Definition of a view A view is a virtual table which does not physically hold data but instead acts like a window into.
ITEC 3220A Using and Designing Database Systems Instructor: Prof. Z. Yang Course Website: 3220a.htm
A SParqly Jython++ A SParqly Jython++ an ASP/SPARQL enhanced Jython Cliff Cheng Carlos Urrutia Francisco Garcia.
Oracle Data Integrator User Functions, Variables and Advanced Mappings
(SQL - Structured Query Language)
CHAPTER 6 LESSON B Creating Custom Forms. Lesson B Objectives  Suppress default system messages  Create alerts and messages to provide system feedback.
CS 111 – Nov. 8 Databases Database Management Systems (DBMS) Structured Query Language (SQL) Commitment –Please review sections 9.1 – 9.2.
PL/SQL programming Procedures and Cursors Lecture 1 [Part 2]
IS6146 Databases for Management Information Systems Lecture 4: SQL IV – SQL Functions and Procedures Rob Gleasure robgleasure.com.
Database Programming Sections 12 – Sequences, Indexes, and Synonymns.
Starting with Oracle SQL Plus. Today in the lab… Connect to SQL Plus – your schema. Set up two tables. Find the tables in the catalog. Insert four rows.
 CONACT UC:  Magnific training   
Rob Gleasure robgleasure.com
Task oriented processing
Database Systems: Design, Implementation, and Management Tenth Edition
ORACLE SQL Developer & SQLPLUS Statements
Chapter 5 Sequences.
Rob Gleasure robgleasure.com
Database Processing: David M. Kroenke’s Chapter Seven:
Contents Preface I Introduction Lesson Objectives I-2
Chapter 8 Advanced SQL.
Database Systems: Design, Implementation, and Management Tenth Edition
Presentation transcript:

Oracle’s take on joins Where it differs from ANSI standard

ANSI Standard SQL join Select supplier_name, Stock_description from supplier join stock on supplier.supplier_id = stock.supplier_id; This also works in Oracle 10g, but Oracle’s native method is…

Oracle SQL join Select supplier_name, Stock_description from supplier, stock where supplier.supplier_id = stock.supplier_id; If you followed the relational algebra discussion in Semester 1, you will know that this is a selection and a projection on a Cartesian product

This makes it easy… To do an inequality join: –Select

Outer join This shows us all the data from one table and anything that joins it from another table: –E.g. all the customers and any orders they have made. –Or All the suppliers and any stock they supply.

Standard outer join Select customer_name, corderno from customer left join corder on customer.customer_id = corder.customer_id; These will work in Oracle, but Oracle prefers:

Oracle outer join Select customer_name, corderno from customer, corder where customer.customer_id(+) = corder.customer_id; –The (+) is on the side that may return nulls.

Exercise Write the query to return all supplier names and the description of the stock they supply, from the builder schema. –Using ‘left join’ –Using (+)

Non-equality joins These concern joins that are NOT necessarily based on referential integrity E.g. –Select all stock for a given supplier (equi-join) where the stock value (i.e. unit_price * stock_level) is less than the amount owed to the supplier (non-equi-join) –Try this in Oracle.

Self-join See the employee example in Tutorial week 11 semester 1, where the employees table has ‘reports to’ field, indicating another row in the same table.

Substitution variables In order to force data entry, a ‘substitution variable’ can be used. This is done by placing an ampersand & in front of the variable name. When SQL*Plus interprets the line, it immediately requests data entry from the user SQL> select * from builder.customer where customer_id = &cid; –SQL* plus will respond by: Enter value for cid: 3

Further uses for substitution variables Substitution variables can be used to replace actual parameters in a procedure call, or even fields: E.g. SQL> Select &fld1,&fld2 from builder.customer; Enter value for fld1: ‘customer_id’ Enter value for fld2: ‘customer_name’

Things to remember When entering values for substitution variables, the same rules apply as when using inserts: –Numerics can be entered without quotes –Strings require single quotes –Dates should be surrounded by single quotes.

Use of ‘ACCEPT’ If you want to change the prompt, you may use the ‘Accept’ command. This command: –Sets up a variable that retains its value for the entire session –Doesn’t use an ampersand (&) –Allows the programmer to design the prompt. E.g. ACCEPT st_code PROMPT: ‘Please enter a 4-character stock code, surrounded by single quotes’;

Script files A script file is an anonymous block. It can be opened and executed, without being saved to the database. Often, you need to run a sequence of SQL statements together, to select, update, insert or delete rows. Sometimes, when a new row is being added, it is necessary to generate a key (e.g. each new student gets a new student number)

Declaring sequences A sequence is an object that is defined in the database and can be incremented whenever a new value (such as a key) is needed. The sequence is created and given a name, an increment, a start value and a possible maximum value. E.g. Create SEQUENCE empIdSeq Incremented by 1 Start with 100 Maxvalue 400; This creates an object empIdSeq of type Sequence in the database. To get rid of it, you must DROP SEQUENCE empIdSeq To use it: Insert into staff values (empIdSeq.nextval,’Harry’,’Foreman’); To see what the current value is; Select empIdSeq.currval from DUAL;

The full syntax for a sequence Create sequence sequencename Increment by n Maxvalue x / NoMaxValue Minvalue m / nominvalue Cycle / nocycle when max is reached, start at min again / not Cache c / nocache Oracle pre-generates and saves numbers in main memory. / not Order / noorder The numbers are generated in chronological order / not

Creating Indexes Sometimes it is necessary to look up data in an order that is not related to the key. To do this, an index can be used: E.g. CREATE INDEX ORDDATE ON SORDER (DELIVEREDDATE); This allows us to look up the orders by the date on which they were delivered. If I were in charge of taking in orders, this index may suit me very well. –Only use indexes when considered absolutely necessary. Every insert or delete must update any indexes that are declared for the table.