Database Technology Jing Shen.

Slides:



Advertisements
Similar presentations
Basic SQL Introduction Presented by: Madhuri Bhogadi.
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.
SQL*PLUS, PLSQL and SQLLDR Ali Obaidi. SQL Advantages High level – Builds on relational algebra and calculus – Powerful operations – Enables automatic.
8 Copyright © Oracle Corporation, All rights reserved. Manipulating Data.
A Guide to Oracle9i1 Advanced SQL And PL/SQL Topics Chapter 9.
SQL Within PL / SQL Chapter 4. 2 SQL Within PL / SQL SQL Statements DML in PL / SQL Pseudocolums Transaction Control.
PL/SQL and the Table API. Benefits of Server-Side Code Speedy Pizza MENU NAPOLITAINE PIZZA Reduced network traffic Maintainability Data integrity Triggers.
Bordoloi and Bock CURSORS. Bordoloi and Bock CURSOR MANIPULATION To process an SQL statement, ORACLE needs to create an area of memory known as the context.
PL / SQL P rocedural L anguage / S tructured Q uery L anguage Chapter 7 in Lab Reference.
CPS120: Introduction to Computer Science Information Systems: Database Management Nell Dale John Lewis.
Project Implementation for COSC 5050 Distributed Database Applications Lab2.
RDB/1 An introduction to RDBMS Objectives –To learn about the history and future direction of the SQL standard –To get an overall appreciation of a modern.
Chapter 7 Advanced SQL Database Systems: Design, Implementation, and Management, Sixth Edition, Rob and Coronel.
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.
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
INTRODUCTION TO PL/SQL. Class Agenda Introduction Introduction to PL/SQL Declaring PL/SQL Variable Creating the Executable Section Interacting with the.
1 Copyright © 2004, Oracle. All rights reserved. Introduction to PL/SQL.
Stored procedures1 Stored procedures and functions Procedures and functions stored in the database.
Overview · What is PL/SQL · Advantages of PL/SQL · Basic Structure of a PL/SQL Block · Procedure · Function · Anonymous Block · Types of Block · Declaring.
In Oracle.  A PL/SQL block stored in the database and fired in response to a specified event ◦ DML statements : insert, update, delete ◦ DDL statements.
Objectives After completing this lesson, you should be able to do the following: Describe each data manipulation language (DML) statement Insert rows.
Lecture2: Database Environment Prepared by L. Nouf Almujally 1 Ref. Chapter2 Lecture2.
Programmatic SQL Shaista Khan CS 157B. Topic Embedded SQL statements in high-level programming languages.
1 Copyright © 2004, Oracle. All rights reserved. Introduction to PL/SQL.
CIS4368: Advanced DatabaseSlide # 1 PL/SQL Dr. Peeter KirsSpring, 2003 PL/SQL.
8 1 Chapter 8 Advanced SQL Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
BIS Database Systems School of Management, Business Information Systems, Assumption University A.Thanop Somprasong Chapter # 8 Advanced SQL.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Trigger Oracle PL/SQL. Triggers Associated with a particular table Associated with a particular table Automatically executed when a particular event occurs.
Database Application Development using PL/SQL Programming.
Database Management COP4540, SCS, FIU Oracle PL/SQL (Ch 10.5)
SQL Basic. What is SQL? SQL (pronounced "ess-que-el") stands for Structured Query Language. SQL is used to communicate with a 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.
School of Computing and Management Sciences © Sheffield Hallam University SQL is non-procedural –designed to be relatively approachable to non- programmers.
What is a Package? A package is an Oracle object, which holds other objects within it. Objects commonly held within a package are procedures, functions,
Using SQL in PL/SQL ITEC 224 Database Programming.
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,
Chapter 8 Advanced SQL Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
ITEC 224 Database Programming PL/SQL Lab Cursors.
Chapter 4 An Introduction to SQL. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.4-2 Topics in this Chapter SQL: History and Overview The.
Introduction to Explicit Cursors. 2 home back first prev next last What Will I Learn? Distinguish between an implicit and an explicit cursor Describe.
Retrieving Data in PL/SQL. 2 home back first prev next last What Will I Learn? In this lesson, you will learn to: –Recognize the SQL statements that can.
implicit and an explicit cursor
Using SQL in PL/SQL Oracle Database PL/SQL 10g Programming Chapter 4.
Relational Database Management System(RDBMS) Structured Query Language(SQL)
Oracle10g Developer: PL/SQL Programming1 Objectives Named program units How to identify parameters The CREATE PROCEDURE statement Creating a procedure.
Text TCS INTERNAL Oracle PL/SQL – Introduction. TCS INTERNAL PL SQL Introduction PLSQL means Procedural Language extension of SQL. PLSQL is a database.
Oracle 10g Database Administrator: Implementation and Administration Chapter 10 Basic Data Management.
Program with PL/SQL Lesson 3. Interacting with the Oracle Server.
Introduction to PL/SQL N. Dimililer. About PL/SQL –PL/SQL is an extension to SQL with design features of programming languages. –Data manipulation and.
LECTURE TWO Introduction to Databases: Data models Relational database concepts Introduction to DDL & DML.
Chapter 4 An Introduction to SQL. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.4-2 Topics in this Chapter SQL: History and Overview The.
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.
Oracle 11g: SQL Chapter 5 Data Manipulation and Transaction Control.
Insert, update, delete TCL. Data Manipulation Language – A DML statement is executed when you: Add new rows to a table Modify existing rows in a table.
Pl/SQL LANGUAGE MULITPLE CHOICE QUESTION SET-3
Interacting with the Oracle Server
Active Database Concepts
Interacting with the Oracle Server
SQL PL/SQL Presented by: Dr. Samir Tartir
JDBC.
Database Management Systems 2
Database Fundamentals
PL/SQL Programing : Triggers
Database systems Lecture 3 – SQL + CRUD
Data Model.
1 Manipulating Data. 2 Objectives After completing this lesson, you should be able to do the following:  Describe each data manipulation language (DML)
Chapter 8 Advanced SQL.
PL/SQL Declaring Variables.
Presentation transcript:

Database Technology Jing Shen

Topics Introductions SQL Statements View Store Procedure/Functions Triggers Example of Object-Oriented Relational DB

SQL has several parts DDL – Data Definition Language DML – Data Manipulation Language Embedded SQL – Designed for use within a host language Authorization or DCL – Data Control Language Integrity

Define Database and DBMS Database: A collection of related data. DBMS: A set of programs that enable users to create and maintain a database.

Data Models It is a collection of concepts that can be used to describe the structure of a database. Conceptual Data Model Physical Data Model Representational (or Implementation) Data Model

Three types of Representational Data Model Relational Data Model Hierarchical Data Model Network Data Model

DML (Data Manipulation Language) INSERT – insert into table_name[(column, [column]…)] {values ( expr[,expr]…) | subquery} DELETE – delete [From] table_name [WHERE condition] Update – update table_name set field = [, field = , …] [ WHERE condition ];

Transaction A transaction is a sequence of SQL statements that Oracle treats as a single unit. COMMIT; ROLLBACK; “autocommit” is set on

SQL Join The INNER JOIN returns all rows from both tables where there is a match. Example: SELECT Employees.Name, Orders.Product FROM Employees INNER JOIN Orders ON Employees.ID = Orders.ID

Joining a table to itself Return all the results where the attribute is in the same table. Example: select s1.s#, s2.s# from s s1, s s2 where s1.city = s2.city and s1.s#<s2.s#; Get all pairs of supplier numbers such that the two suppliers are located in the same city.

Continues… The LEFT JOIN returns all the rows from the first table (Employees), even if there are no matches in the second table (Orders). Example: SELECT Employees.Name, Orders.Product FROM Employees LEFT JOIN Orders ON Employees.ID = Orders.ID

Continues… The RIGHT JOIN returns all the rows from the second table (Orders), even if there are no matches in the first table (Employee). Example: SELECT Employees.Name, Orders.Product FROM Employees RIGHT JOIN Orders ON Employees.ID = Orders.ID

View A view is logical table Data does not physically exist (no storage) Views are defined in terms of base tables “created by SELECT statement”

Store Procedures It allows for sharing o PL/SQL code by different applications running at different places. Syntax: create [or replace] procedure <proc-name> [(<parameter-list>)] as <declarations> begin <executable-section> end; Function: create [or replace] function <func-name> [(<parameter-list>)] return <datatype> as

Example of how user defined exceptions Set serveroutput on; declare incorrect_first_name exception; fname employee.first_name%type; lname employee.last_name%type; cursor a is select last_name, first_name from employee; begin open a; loop fetch a into lname, fname; dbms_output.put_line (fname); if (a%notfound) then exit; end if; if (fname = ‘ELINOR’) then raise incorrect_first_name; end loop; exception when incorrect_first_name then dbms-output.put_line (“Wrong spelling.”); end;

Example of Function P4.sql: DECLARE enum customers.cno%type; total number(10,2); status boolean; function total_emp_sales( emp_no IN employees.eno%type) return number is sales number; begin select sum(price*qty) into sales from orders,odetails,parts where orders.eno = emp_no and orders.ono = odetails.ono and odetails.pno = parts.pno; return (sales); end; BEGIN enum := 1000; total := total_emp_sales(enum); DBMS_OUTPUT.PUT_LINE('Total sales for employee ' || enum || ' is ' || total); END; /

Trigger It is a mechanism that automatically executes a specified PL/SQL block when a triggering event occurs on a table. The triggering event may be one of insert, delete, or update.

Example of Triggers CREATE OR REPLACE TRIGGER delete_orders BEFORE DELETE ON orders FOR EACH ROW BEGIN DELETE FROM odetails WHERE ono = :old.ono; END; /

Packages A package is a group of related PL/SQL objects (variables, constants, types, and cursors), procedures, and functions that is stored in the database. It consists of two parts: Package specification and the package body.

Example of Package create or replace package process_orders as procedure add_order_details (onum IN odetails.ono%type, pnum IN odetails.pno%type, quantity IN odetails.qty%type); procedure add_order (onum IN orders.ono%type, cnum IN orders.cno%type, enum IN orders.eno%type, receive IN date); procedure ship_order ship IN date); end; /

Example of Relational/Object-Oriented Database Structure

References: http://www.w3schools.com/sql/sql_join.asp Oracle Book