DataBase Logic in Business Applications

Slides:



Advertisements
Similar presentations
PL/SQL.
Advertisements

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.
AN INTRODUCTION TO PL/SQL Mehdi Azarmi 1. Introduction PL/SQL is Oracle's procedural language extension to SQL, the non-procedural relational database.
SQL*PLUS, PLSQL and SQLLDR Ali Obaidi. SQL Advantages High level – Builds on relational algebra and calculus – Powerful operations – Enables automatic.
Chapter 4B: More Advanced PL/SQL Programming
Advanced Package Concepts. 2 home back first prev next last What Will I Learn? Write packages that use the overloading feature Write packages that use.
Programming in Oracle with PL/SQL
Introduction to PL/SQL Lecture 0 – Self Study Akhtar Ali.
PL/SQL block has the following structure: DECLARE Declaration statements BEGIN Executable statements EXCEPTION Exception-handling statements END ;
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.
Cursor and Exception Handling By Nidhi Bhatnagar.
Oracle10g Developer: PL/SQL Programming1 Objectives Manipulating data with cursors Managing errors with exception handlers Addressing exception-handling.
Chapter 4 Cursors and Exception Handling Oracle10g Developer:
Exceptions Oracle Database PL/SQL 10g Programming Chapter 7.
EE Copyright س Oracle Corporation, All rights reserved. ® Review of PL/SQL.
I Copyright © 2004, Oracle. All rights reserved. Introduction Copyright © 2004, Oracle. All rights reserved.
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.
PRACTICE OVERVIEW PL/SQL Part Examine this package specification and body: Which statement about the V_TOTAL_BUDGET variable is true? A. It must.
CS178 Database Management PL/SQL session 8 References: ORACLE 9i PROGRAMMING A Primer Rajshekhar Sunderraman.
Oracle PL/SQL. PL/SQL Originally modeled after ADA Originally modeled after ADA Created for Dept. of DefenseCreated for Dept. of Defense Allows expanded.
1 Copyright © 2004, Oracle. All rights reserved. Introduction to PL/SQL.
Trapping Oracle Server Exceptions. 2 home back first prev next last What Will I Learn? Describe and provide an example of an error defined by the Oracle.
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.
PL/SQL Block Structure DECLARE - Optional Variables, cursors, user-defined exceptions BEGIN - Mandatory SQL Statements PL/SQL Statements EXCEPTIONS - Optional.
Manipulating Data in PL/SQL. 2 home back first prev next last What Will I Learn? Construct and execute PL/SQL statements that manipulate data with DML.
Chapter 15 Introduction to PL/SQL. Chapter Objectives  Explain the benefits of using PL/SQL blocks versus several SQL statements  Identify the sections.
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.
Oracle 8i Exception Handling. General Syntax DECLARE --- BEGIN --- EXCEPTION WHEN exception_name1 THEN -Error handling statements WHEN exception_name2.
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.
Chapter 9: Advanced SQL and PL/SQL Guide to Oracle 10g.
1 Handling Exceptions Part F. 2 Handling Exceptions with PL/SQL What is an exception? Identifier in PL/SQL that is raised during execution What is an.
Chapter 16 Cursors and Exceptions. Chapter Objectives  Determine when an explicit cursor is required  Declare, open, and close an explicit cursor 
DATABASE PROGRAMS CS 260 Database Systems. Overview  Introduction  Anonymous blocks  Oracle’s PL/SQL language basics  Conditions and loops  Cursors.
implicit and an explicit cursor
Chapter 18: Exception Handling1 Chapter Eighteen Exception Handling Objective: – Define exceptions – List types of exception handlers – Trap errors – Exception.
Handling Exceptions. Objectives What is exception Types of exceptions How to handle exceptions Trapping pre defined oracle errors.
A procedure is a module performing one or more actions; it does not need to return any values. The syntax for creating a procedure is as follows: CREATE.
Oracle10g Developer: PL/SQL Programming1 Objectives Named program units How to identify parameters The CREATE PROCEDURE statement Creating a procedure.
Copyright  Oracle Corporation, All rights reserved. 23 Handling Exceptions.
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.
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.
1 Copyright © 2004, Oracle. All rights reserved. PL/SQL Programming Concepts: Review.
DataBase Logic in Business Applications
ITEC 224 Database Programming
Pl/SQL LANGUAGE MULITPLE CHOICE QUESTION SET-3
DataBase Logic in Business Applications
Interacting with the Oracle Server
DataBase Logic in Business Applications
Oracle11g: PL/SQL Programming Chapter 4 Cursors and Exception Handling.
Oracle9i Developer: PL/SQL Programming Chapter 3 PL/SQL Processing.
Handling Exceptions.
Database Programming PL SQL.
SQL PL/SQL Presented by: Dr. Samir Tartir
PL/SQL – Session 1 of 4 Instructor: Jim Cody
PL/SQL Scripting in Oracle:
Handling Exceptions.
Handling Exceptions.
Chapter 8 Advanced SQL.
PL/SQL Declaring Variables.
MATERI PL/SQL Procedures Functions Packages Database Triggers
Database Programming Using Oracle 11g
Presentation transcript:

DataBase Logic in Business Applications Al.I. Cuza University of Iași Faculty of Economics and Business Administration Department of Accounting, Information Systems and Statistics DataBase Logic in Business Applications Oracle PL/SQL. Procedures, Functions, Queries, Exceptions, Cursors By Marin Fotache & Co.

Agenda PL/SQL block general format (recap.) General syntax and rules for procedures and functions Recursivity (1) Indirect variable declaration (%TYPE, %ROWTYPE) Using queries (SELECT) in PL/SQL blocks Error treatment (exceptions) Implicit cursor Explicit cursors

PL/SQL Blocks Format

General Format of Anonymous Blocks, Procedures, and Functions

PL/SQL Procedures and Functions Procedures DO some actions, processing Functions return values or set of values Both procedures and functions can be called (invoked) from: Anonymous PL/SQL blocks Other stand-alone procedures and functions Procedures and functions within a package body Triggers External modules written in .NET, Java, PHP, etc. Additionally, some functions can be used in SELECT queries. Cautions: Their returned values must conform to the query result structure Purity levels (some functions must not update the tables they query)

Queries within PL/SQL blocks. Indirect variable declaration

Exceptions The name of the errors in PL/SQL When error occurs, block execution jumps to the EXCEPTION section and then the block terminates In order to treat the errors and resume the execution, blocks must be nested

Exception Example (http://www.tutorialspoint.com)

Examples of Predefined Exceptions NO_DATA_FOUND TOO_MANY_ROWS DUP_VAL_ON_INDEX ROWTYPE_MISMATCH PROGRAM_ERROR CASE_NOT_FOUND VALUE_ERROR ZERO_DIVIDE LOGIN_DENIED NOT_LOGGED_ON

User-Defined Exception (http://www.tutorialspoint.com)

Recursivity (1) CREATE OR REPLACE FUNCTION f_n_th_from_fibonacci (n IN INTEGER) RETURN INTEGER IS BEGIN IF n = 1 THEN RETURN 0 ; END IF ; IF n = 2 THEN RETURN 1 ; RETURN f_n_th_from_fibonacci (n - 2) + f_n_th_from_fibonacci ( n - 1 ) ; END ; /

Cursors Vital ingredient in database application development Common to all major database programming languages Stardardized in SQL (since SQL:1999) Implicit cursors provide information about the result of the most recent launched query Explicit cursor are the main tool for tables records sequential processing Used extensively by the database programmers

Implicit cursors Automatically created by execution of a DML SQL statemeNt (INSERT...SELECT, UPDATE, DELETE) Keep information about the most recent statement execution BEGIN UPDATE liniifact SET Linie = Linie + 1 WHERE NrFact=1111 AND Linie > 1 ; DBMS_OUPUT.PUT_LINE ( 'Au fost modificate' || SQL%ROWCOUNT || ' linii ') ; END ;

Implicit Cursor Attributes (Properties)

Explicit Cursors – Syntax 1

Explicit Cursors – Syntax 2

Parameterized Cursors

WHERE CURRENT OF Clause

Useful Resources Getting started PL/SQL tutorial http://www.way2tutorial.com/plsql/tutorial.php PL/SQL Tutorial (TutorialsPoint) http://www.tutorialspoint.com/plsql/index.htm pl/sql tutorial http://plsql-tutorial.com PL/SQL Tutorial http://www.plsqltutorial.com Fotache et. 2003, Fotache 2009 (in Romanian) - uploaded on FEAA portal) Steven Feuerstein - Working with Cursors, Oracle Magazine, March/April 2013, http://www.oracle.com/technetwork/issue-archive/2012/12-jul/o42plsql- 1653077.html Steven Feuerstein - Working with Records, Oracle Magazine, May/June 2012, http://www.oracle.com/technetwork/issue-archive/2012/12-may/o32plsql- 1578019.html

Video-tutorials An older video-tutorial (in Romanian): 04_Proceduri functii SELECT exceptii cursoare.mp4 https://1drv.ms/v/s!AgPvmBEDzTOSwlwA6IclMmi63jzq PL21 PLSQL Tutorial Implicit Cursors https://www.youtube.com/watch?v=sv7bEUs8rlw PL22 PL SQL Tutorial Implicit Cursors Hands On) https://www.youtube.com/watch?v=JNFmiQNbJRM PL23 PLSQL Tutorial Explicit cursors in PL SQL blocks Theory) https://www.youtube.com/watch?v=84104L3NnuY&spfreload=10 PL24 PL SQL Tutorial Explicit Cursors Hands on) https://www.youtube.com/watch?v=ARuIyRd6qg4&spfreload=10 PL25 PLSQL Tutorial %TYPE and %ROWTYPE attributes https://www.youtube.com/watch?v=vawx8CjftOo

Video-tutorials (cont.) See also the following video-tutorials in the playlist: https://www.youtube.com/playlist?list=PL3245012E063 1F7AE&spfreload=10 PLS-21: PL/SQL Stored Procedure PLS-22: Using Parameters in PL/SQL Procedure PLS-23: PL/SQL Stored Functions PLS-17: Predefined Exceptions in Oracle PLS-18: Non Predefined Exceptions in PL/SQL PLS-19: User Defined Exceptions in PL/SQL PLS-9: Oracle PL/SQL Cursor PLS-10: Oracle Pl/SQL Cursors With Parameters PLS-11: Oracle PL/SQL Reference Cursor PLS-13: PL/SQL Records Data Type