SQL*PLUS, PLSQL and SQLLDR Ali Obaidi. SQL Advantages High level – Builds on relational algebra and calculus – Powerful operations – Enables automatic.

Slides:



Advertisements
Similar presentations
Owners Roles DB Objects Grant Revoke Grant Revoke Grant Revoke (*) with admin option Il ruolo …. È un set di system & object privileges Non appartiene.
Advertisements

8 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Using Explicit Cursors.
PL/SQL.
Chapter 8 Advanced SQL Pearson Education © Chapter 8 - Objectives u How to use the SQL programming language u How to use SQL cursors u How to create.
BD05/06 PL/SQL  Introduction  Structure of a block  Variables and types  Accessing the database  Control flow  Cursors  Exceptions  Procedures.
H.Melikian1 PLSQL Dr.Hayk Melikyan Departmen of Mathematics and CS
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.
Stored Procedure Language Stored Procedure Overview Stored Procedure is a function in a shared library accessible to the database server can also write.
PL/SQL Agenda: Basic PL/SQL block structure
Oracle PL/SQL Eyad Husni Elshami. Why PL/SQL Block Structures: – PL/SQL consists of blocks of code, which can be nested within each other. Each block.
A Guide to SQL, Seventh Edition. Objectives Embed SQL commands in PL/SQL programs Retrieve single rows using embedded SQL Update a table using embedded.
Introduction to PL/SQL Lecture 0 – Self Study Akhtar Ali.
1 PL/SQL programming Procedures and Cursors Lecture 1 Akhtar Ali.
Cursors in Pl/SQL Database 1. Practice. Sample Database The schema of the sample database is the following: Drinkers (name, occupation, birthday, salary)
SEMESTER 1, 2013/2014 DB2 APPLICATION DEVELOPMENT OVERVIEW.
Introduction to PL/SQL. Procedural Language extension for SQL Oracle Proprietary 3GL Capabilities Integration of SQL Portable within Oracle data bases.
Advanced Databases Advanced PL/SQL Programming: Procedure, Function and Package.
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.
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.
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.
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 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Cursors These slides are licensed under.
PL/SQL A BRIEF OVERVIEW DAVID WILSON. PL/SQL User’s Guide and Reference PL/SQL User’s Guide and Reference.
PL/SQL Cursors Session - II. Attributes Attributes %TYPE %ROWTYPE % Found % NotFound % RowCount % IsOPen %TYPE %ROWTYPE % Found % NotFound % RowCount.
PL SQL Block Structures. What is PL SQL A good way to get acquainted with PL/SQL is to look at a sample program. PL/SQL combines the data manipulating.
Advanced SQL: Cursors & Stored Procedures
Advanced SQL Instructor: Mohamed Eltabakh 1 Part II.
Stored Procedures Week 9. Test Details Stored Procedures SQL can call code written in iSeries High Level Languages –Called stored procedures SQL has.
1 CursorsCursors. 2 SQL Cursor A cursor is a private SQL work area. A cursor is a private SQL work area. There are two types of cursors: There are two.
1 Copyright © 2004, Oracle. All rights reserved. Introduction to PL/SQL.
CIS4368: Advanced DatabaseSlide # 1 PL/SQL Dr. Peeter KirsSpring, 2003 PL/SQL.
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.
Chapter 15 Introduction to PL/SQL. Chapter Objectives  Explain the benefits of using PL/SQL blocks versus several SQL statements  Identify the sections.
PL/SQL. Introduction to PL/SQL block Declare declarations Begin executable statement Exception exception handlers End;
Database Management COP4540, SCS, FIU Oracle PL/SQL (Ch 10.5)
Database Technology Jing Shen.
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,
Chapter 9: Advanced SQL and PL/SQL Guide to Oracle 10g.
ITEC 224 Database Programming PL/SQL Lab Cursors.
Oracle10g Developer: PL/SQL Programming1 Objectives SQL queries within PL/SQL Host or bind variables The %TYPE attribute Include queries and control structures.
Introduction to Explicit Cursors. 2 home back first prev next last What Will I Learn? Distinguish between an implicit and an explicit cursor Describe.
Oracle11g: PL/SQL Programming Chapter 3 Handling Data in PL/SQL Blocks.
implicit and an explicit cursor
PL/SQL programming Procedures and Cursors Lecture 1 [Part 2]
Text TCS INTERNAL Oracle PL/SQL – Introduction. TCS INTERNAL PL SQL Introduction PLSQL means Procedural Language extension of SQL. PLSQL is a database.
Program with PL/SQL Lesson 3. Interacting with the Oracle Server.
Chapter 8 Advanced SQL Pearson Education © Chapter 8 - Objectives How to use the SQL programming language How to use SQL cursors How to create stored.
Advanced SQL: Cursors & Stored Procedures Instructor: Mohamed Eltabakh 1.
Kingdom of Saudi Arabia Ministry of Higher Education Al-Imam Muhammad Ibn Saud Islamic University College of Computer and Information Sciences Overview.
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.
CS422 Principles of Database Systems Oracle PL/SQL Chengyu Sun California State University, Los Angeles.
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe.
CS422 Principles of Database Systems Stored Procedures and Triggers Chengyu Sun California State University, Los Angeles.
1 Copyright © 2004, Oracle. All rights reserved. PL/SQL Programming Concepts: Review.
A Guide to SQL, Seventh Edition
PL/SQL.
Database Systems: Design, Implementation, and Management Tenth Edition
Chapter 5: Advanced SQL Database System concepts,6th Ed.
Introduction to PL/SQL Procedures & Cursors
Chapter 2 Handling Data in PL/SQL Blocks Oracle9i Developer:
Chapter 8 Advanced SQL.
PL/SQL Declaring Variables.
Chapter 8 Advanced SQL Pearson Education © 2009.
Stored Procedure Language
Presentation transcript:

SQL*PLUS, PLSQL and SQLLDR Ali Obaidi

SQL Advantages High level – Builds on relational algebra and calculus – Powerful operations – Enables automatic optimization Table oriented – Direct representation and manipulation as bags of rows Standardized – ANSI standards – Compatibility across vendors Gateway to other languages – Embeddings in 3GL languages (e.g. C++) – Client software via ODBC, JDBC

PL/SQL A Procedural Extension To SQL – Procedural, statement oriented –Blocks, declarations, assignable variables, conditionals, iterations, exceptions – Subprograms –Procedures, functions – Packages –With specification separate from body – Composite datatypes –Rows, cursors, records (structs), tables (arrays)

Achievements Modular, Reusable Database Manipulation and Maintenance Code Stored objects –Procedures, functions packages External procedures –PL/SQL code invoked from 3GL languages Triggers Stored procedures invoked by insert, delete, update Crucial for integrity maintenance

Using PL/SQL From SQL*Plus Execute the following to enable printing –set serveroutput on Defining procedures –Since procedures, functions and packages are objects, use : create Do a drop first –create or replace –Type in source code, execute by single line containing “/” Can also input from source file –start Examine syntax errors by –show errors

Example SQL> declare i integer; j integer; begin i := 0; for j in loop i := i+j; end loop; dbms_output.put_line(i); end; /

Cursors Cursors allow embedded SQL statements –Result is a set (table) in a temporary work area Cursor name permits iterative manipulation of rows Two varieties of cursors –Implicit Quick to write For simple iteration of resulting row set –Explicit More detailed to write Permit more advanced manipulations

Example SQL> create or replace procedure sumsalary IS cursor c1 is select * from employee; salsum integer; begin salsum := 0; for emp_rec in c1 loop salsum := salsum + emp_rec.salary; end loop; dbms_output.put_line('Salary sum: ' || salsum); end; 13 / SQL> exec sumsalary Salary sum:

Explicit Cursor Operations Declare –Introduces cursor object, bound to SQL statement OPEN –Constructs temporary table FETCH –Accesses next row Tests – %FOUND, %NOTFOUND, %ROWCOUNT, %ISOPEN CLOSE –Releases temporary table and associated working data

SQL> DECLARE CURSOR c1(min_salary integer) IS SELECT name FROM employee WHERE salary > min_salary; PROCEDURE count_salaries(m_s integer) IS emp_rec c1%ROWTYPE; how_many integer := 0; BEGIN OPEN c1(m_s); FETCH c1 INTO emp_rec; WHILE c1%FOUND LOOP how_many := how_many + 1; FETCH c1 INTO emp_rec; END LOOP; dbms_output.put_line(how_many || ' employees have salary > '17 || m_s); CLOSE c1; END; BEGIN count_salaries(40000); count_salaries(60000); END; / 5 employees have salary > employees have salary > 60000

Relational Data Model  Defined by Edgar Codd in 1970  Considered ingenious but impractical  Conceptually simple  Relational DB is perceived as a collection of tables  Provides SQL, a 4GL

Functions In PL/SQL SQL> create or replace function f(i in integer) return integer IS begin return i*i; end; / Function created. SQL> exec dbms_output.put_line(f(13)); 169