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

Slides:



Advertisements
Similar presentations
8 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Using Explicit Cursors.
Advertisements

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.
SQL*PLUS, PLSQL and SQLLDR Ali Obaidi. SQL Advantages High level – Builds on relational algebra and calculus – Powerful operations – Enables automatic.
INTRODUCTION TO ORACLE Lynnwood Brown System Managers LLC Introduction to PL/SQL – Lecture 6.
Stored Procedure Language Stored Procedure Overview Stored Procedure is a function in a shared library accessible to the database server can also write.
Embedded SQL John Ortiz. Lecture 15Embedded SQL2 Why Isn’t Interactive SQL Enough?  How to do this using interactive SQL?  Print a well-formatted transcript.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 13 Introduction to SQL Programming Techniques.
Triggers The different types of integrity constraints discussed so far provide a declarative mechanism to associate “simple” conditions with a table such.
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.
Using Oracle PL/SQL PL/SQL stands for Procedural Language/SQL. PL/SQL extends SQL by adding constructs found in procedural languages, resulting in a structural.
System Administration Accounts privileges, users and roles
A Guide to Oracle9i1 Advanced SQL And PL/SQL Topics Chapter 9.
Introduction to PL/SQL Lecture 0 – Self Study Akhtar Ali.
1 PL/SQL programming Procedures and Cursors Lecture 1 Akhtar Ali.
SEMESTER 1, 2013/2014 DB2 APPLICATION DEVELOPMENT OVERVIEW.
Advanced Databases Advanced PL/SQL Programming: Procedure, Function and Package.
PL / SQL P rocedural L anguage / S tructured Q uery L anguage Chapter 7 in Lab Reference.
Overview of JDBC and Pro*C 1 Overview of JDBC,Pro*C and Oracle connectivity on Omega CSE 5330 – Database Systems.
Cursor and Exception Handling By Nidhi Bhatnagar.
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.
CSE 3330 Database Concepts Stored Procedures. How to create a user CREATE USER.. GRANT PRIVILEGE.
Overview of JDBC and Pro*C 1 CSE 5330 – Database Systems.
PL/SQL CSE2132 Database Systems Week 9 Lecture PL/SQL and Programming in Oracle - 2.
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.
Triggers and Stored Procedures in DB 1. Objectives Learn what triggers and stored procedures are Learn the benefits of using them Learn how DB2 implements.
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.
Lecture 8 Creating Stored Functions. Objectives  After completing this lesson, you should be able to do the following:  What is Function?  Types of.
ICS 321 Fall 2009 DBMS Application Programming Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa 10/06/20091Lipyeow.
ICS 321 Fall 2010 SQL in a Server Environment (i) Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa 11/1/20101Lipyeow.
Copyright  Oracle Corporation, All rights reserved. 7 Accessing a Database Using SQLJ.
Programmatic SQL Shaista Khan CS 157B. Topic Embedded SQL statements in high-level programming languages.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
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 8 Advanced SQL Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Implementing The Middle Tier These slides.
Dr Gordon Russell, Napier University Unit Embedde SQL - V2.0 1 Embedded SQL Unit 5.1.
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 
Professor: Dr. Shu-Ching Chen TA: Hsin-Yu Ha Function, Trigger used in PosgreSQL.
PL/SQL programming Procedures and Cursors Lecture 1 [Part 2]
PRACTICE OVERVIEW PL/SQL Part Your stored procedure, GET_BUDGET, has a logic problem and must be modified. The script that contains the procedure.
Text TCS INTERNAL Oracle PL/SQL – Introduction. TCS INTERNAL PL SQL Introduction PLSQL means Procedural Language extension of SQL. PLSQL is a database.
Lu Wei1 Outline Introduction Basic SQL Setting Up and Using PostgreSQL Advanced SQL Embeded SQL.
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.
Creating Functions. Overview of Stored Functions A function is a named PL/SQL block that returns a value. A function is a named PL/SQL block that returns.
What Are Subprograms? Subprograms are named PL/SQL blocks that can take parameters and be invoked. Subprograms allow decomposition of a program into logical.
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe.
Oracle9i Developer: PL/SQL Programming Chapter 6 PL/SQL Packages.
6 Copyright © 2009, Oracle. All rights reserved. Using Dynamic SQL.
Introduction to SQL Programming Techniques
Creating Stored Functions
PL/SQL.
UNIT - V STORED PROCEDURE.
REF Cursors.
DB2.
PRACTICE OVERVIEW PL/SQL Part - 2.
PRACTICE OVERVIEW PL/SQL Part - 1.
Chapter 8 Advanced SQL.
MATERI PL/SQL Procedures Functions Packages Database Triggers
Chapter 8 Advanced SQL Pearson Education © 2009.
Prof. Arfaoui. COM390 Chapter 7
Stored Procedure Language
Presentation transcript:

Owners Roles DB Objects Grant Revoke Grant Revoke Grant Revoke (*) with admin option Il ruolo …. È un set di system & object privileges Non appartiene ad alcuno schema Può essere grantato ad un owner oppure ad un altro ruolo Può essere enabled / disabled È integralmente descritto nel dizionario dati

What Is an Oracle Precompiler? An Oracle Precompiler is a programming tool that allows you to embed SQL statements in a high-level source program. The precompiler accepts the source program as input, translates the embedded SQL statements into standard Oracle runtime library calls, and generates a modified source program that you can compile, link, and execute in the usual way. Sorgente LP + SQL Precompilato LP Precompilazione Codice oggetto Compilazione Eseguibile Librerie (del DBMS) Collegamento

#include main(){ exec sql begin declare section; char *NomeDip = "Manutenzione"; char *CittaDip = Torino"; int NumeroDip = 20; exec sql end declare section; exec sql connect to if (sqlca.sqlcode != 0) { printf("Connessione al DB non riuscita\n"); } else { exec sql insert into Dipartimento values(:NomeDip,:CittaDip,:NumeroDip); exec sql disconnect all; } }

PL/SQL, Oracles procedural extension of SQL Advanced fourth-generation programming language (4GL)

Advantages of PL/SQL PL/SQL is a completely portable, high-performance transaction processing language that offers the following advantages: - Support for SQL - Support for object-oriented programming - Better performance - Higher productivity - Full portability - Tight integration with Oracle - Tight security

PL/SQL Program Constructs Anonymous block Database trigger Application trigger Stored procedure/ function PackagePackage Application procedure/ function DECLARE BEGIN EXCEPTION END; Object type

PL/SQL Control Structures IF condition THEN sequence_of_statements1 ELSE sequence_of_statements2 END IF; LOOP... IF condition THEN EXIT; END IF; END LOOP; WHILE condition LOOP sequence_of_statements END LOOP; FOR i IN 1..3 LOOP sequence_of_statements END LOOP;

Cursor Programma DBMS Buffer select …

DECLARE BEGIN END; EXCEPTION CURSOR c1 is SELECT ename, empno, sal FROM emp ORDER BY sal DESC; OPEN c1; CLOSE c1; LOOP END LOOP; FETCH c1 EXIT WHEN c1%NOTFOUND; Analyze Data with PL/SQL Code using my_ename, my_empno, my_sal; WHEN OTHERS THEN PL/SQL Code; my_ename VARCHAR2(10); my_empno NUMBER(4); my_sal NUMBER(7,2); INTO my_ename, my_empno, my_sal;

DECLARE BEGIN END; EXCEPTION CURSOR c1 is SELECT ename, empno, sal FROM emp ORDER BY sal DESC; OPEN c1; CLOSE c1; LOOP END LOOP; FETCH c1 EXIT WHEN c1%NOTFOUND; Analyze Data with PL/SQL Code using my_ename, my_empno, my_sal; WHEN OTHERS THEN PL/SQL Code; my_ename emp.ename%TYPE; my_empno emp.empno%TYPE; my_sal emp.sal%TYPE; INTO my_ename, my_empno, my_sal;

DECLARE BEGIN END; EXCEPTION CURSOR c1 is SELECT ename, empno, sal FROM emp ORDER BY sal DESC; OPEN c1; CLOSE c1; LOOP END LOOP; FETCH c1 EXIT WHEN c1%NOTFOUND; Analyze Data with PL/SQL Code using c1_rec.ename …… WHEN OTHERS THEN PL/SQL Code; c1_rec c1%ROWTYPE; INTO c1_rec;

What Are Subprograms? Subprograms are named PL/SQL blocks that can take parameters and be invoked. PL/SQL has two types of subprograms procedures functions. [CREATE [OR REPLACE]] PROCEDURE procedure_name[(parameter[, parameter]...)] [PRAGMA AUTONOMOUS_TRANSACTION;] [local declarations] BEGIN executable statements [EXCEPTION exception handlers] END [name];

What Is a PL/SQL Package? A package is a schema object that groups logically related PL/SQL types, items, and subprograms. Packages usually have two parts, a specification and a body, although sometimes the body is unnecessary.

Advantages of PL/SQL Packages Modularity Easier Application Design Information Hiding Added Functionality Better Performance CREATE OR REPLACE PACKAGE emp_actions AS -- spec TYPE EmpRecTyp IS RECORD (emp_id INT, salary REAL); CURSOR desc_salary RETURN EmpRecTyp; PROCEDURE hire_employee ( ename VARCHAR2, job VARCHAR2, mgr NUMBER, sal NUMBER, comm NUMBER, deptno NUMBER); PROCEDURE fire_employee (emp_id NUMBER); END emp_actions;

CREATE OR REPLACE PACKAGE BODY emp_actions AS -- body CURSOR desc_salary RETURN EmpRecTyp IS SELECT empno, sal FROM emp ORDER BY sal DESC; PROCEDURE hire_employee ( ename VARCHAR2, job VARCHAR2, mgr NUMBER, sal NUMBER, comm NUMBER, deptno NUMBER) IS BEGIN INSERT INTO emp VALUES (empno_seq.NEXTVAL, ename, job, mgr, SYSDATE, sal, comm, deptno); END hire_employee; PROCEDURE fire_employee (emp_id NUMBER) IS BEGIN DELETE FROM emp WHERE empno = emp_id; END fire_employee; END emp_actions;

Dynamic SQL Static SQL statements: do not change from execution to execution. You need dynamic SQL in the following situations: You want to execute a SQL data definition statement (such as CREATE ), a data control statement (such as GRANT ), or a session control statement (such as ALTER SESSION ). In PL/SQL, such statements cannot be executed statically. You want more flexibility. For example, you might want to defer your choice of schema objects until run time. Or, you might want your program to build different search conditions for the WHERE clause of a SELECT statement. A more complex program might choose from various SQL operations, clauses, etc.

EXECUTE IMMEDIATE dynamic_string [INTO {define_variable[, define_variable]... | record}] [USING [IN | OUT | IN OUT] bind_argument [, [IN | OUT | IN OUT] bind_argument]...]; where: dynamic_string is a string expression that represents a SQL statement or PL/SQL block define_variable is a variable that stores a SELECTed column value record is a user-defined or %ROWTYPE record that stores a SELECTed row bind_argument is an expression whose value is passed to the dynamic SQL statement or PL/SQL block.

Using the OPEN-FOR, FETCH, and CLOSE Statements OPEN {cursor_variable | :host_cursor_variable} FOR dynamic_string [USING bind_argument[, bind_argument]...]; FETCH {cursor_variable | :host_cursor_variable} INTO {define_variable[, define_variable]... | record}; CLOSE {cursor_variable | :host_cursor_variable}; Using Cursor Attributes Every cursor has four attributes: %FOUND, %ISOPEN, %NOTFOUND, and %ROWCOUNT. When appended to the cursor name, they return useful information about the execution of static and dynamic SQL statements.

PL/SQL Wrapper The PL/SQL wrapper is a stand-alone utility that hides application internals by converting PL/SQL source code into portable object code. Wrapping offers: Platform independence Dynamic loading Dynamic binding Dependency checking Normal importing and exporting when invoked The PL/SQL wrapper is a stand-alone utility that hides application internals by converting PL/SQL source code into portable object code. Wrapping offers: Platform independence Dynamic loading Dynamic binding Dependency checking Normal importing and exporting when invoked

Examples of Wrapping CREATE PACKAGE banking AS min_bal := 100; no_funds EXCEPTION;... END banking; / WRAP CREATE PACKAGE banking wrapped 012abc463e...