Procedure Function Trigger. create table employee ( id number, name varchar2(100), deptno number, salary float, primary key(id) ) create table deptincrease.

Slides:



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

PL/SQL.
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.
6.830/6.814 Lecture 5 Database Internals Continued September 17, 2014.
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.
ISD3 Lecture 4 - Databases, SQL and MySQL. dept deptno dname location emp empno ename not null job not null hiredate sal comm manager The EMP DEPT database.
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.
PL/SQL Agenda: Basic PL/SQL block structure
1 PL/SQL programming Procedures and Cursors Lecture 1 Akhtar Ali.
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.
Revision on Triggers and Cursors. Walk through of exam type question. Question 1. A trigger is required to automatically update the number of rooms available.
Stored Procedures, Triggers, Program Access Dr Lisa Ball 2008.
Program with PL/SQL. Interacting with the Oracle Server.
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.
Programming in postgreSQL with PL/pgSQL ProceduralLanguageextension topostgreSQL.
제 2 장 SQL 활용.  SQL 활용 예제 (1) create table student ( id int not null, name char(20) not null, age int, height int, weight float, primary key(id) ); insert.
1. 1. Which type of argument passes a value from a procedure to the calling program? A. VARCHAR2 B. BOOLEAN C. OUT D. IN 2.
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.
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.
Advanced SQL: Cursors & Stored Procedures
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 ISYS Triggers. 2 Agenda Triggers Review Correlation identifiers (pseudo records) Restrictions on triggers Trigger usage Mutating tables Enabling.
PL/SQL. Introduction to PL/SQL block Declare declarations Begin executable statement Exception exception handlers End;
SQL SeQueL -Structured Query Language SQL SQL better support for Algebraic operations SQL Post-Relational row and column types,
Advanced SQL: Triggers & Assertions
Dec 8, 2003Murali Mani Constraints B term 2004: lecture 15.
Professor: Dr. Shu-Ching Chen TA: Hsin-Yu Ha Function, Trigger used in PosgreSQL.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Using Data Structures in Embedded Programs.
PL/SQL programming Procedures and Cursors Lecture 1 [Part 2]
Advanced Databases More Advanced PL/SQL Programing 1.
Copyright  Oracle Corporation, All rights reserved. 20 Working with Composite Datatypes.
RETRIEVE A NO. OF ROWS ¦ Declare a cursor ¦ Open the cursor ¦ Fetch rows of data ¦ Stop fetching rows ¦ Close the cursor.
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.
Constraints and Views Chap. 3-5 continued (7 th ed. 5-7)
Database An introduction to using Oracle PL/SQL An introduction to using Oracle PL/SQL An introduction to using Oracle PL/SQL Definition: PL/SQL.
Programming in postgreSQL with PL/pgSQL ProceduralLanguageextension topostgreSQL 1.
CS422 Principles of Database Systems Stored Procedures and Triggers Chengyu Sun California State University, Los Angeles.
Programming in postgreSQL with PL/pgSQL
ISYS Triggers.
Views, Triggers and Recursive Queries
Difference between Oracle PL/SQL and MySQL
SQL PL/SQL Presented by: Dr. Samir Tartir
Prepared Statements Function and Triggers
Agenda Triggers Review Correlation identifiers (pseudo records)
CS4222 Principles of Database System
Interacting with the Oracle Server
Generalization.
ISYS Built-in Functions
جملة الاستعلام الأساسية
Working with Composite Datatypes
ISYS Triggers.
الأزنده أ.موضي المحرج.
Advanced SQL: Views & Triggers
Instructor: Mohamed Eltabakh
Instructor: Mohamed Eltabakh
Chapter 03 DBMS.
Information Management
Chapter 8 Advanced SQL Pearson Education © 2009.
Triggers.
Stored Procedure Language
Database Programming Using Oracle 11g
Database Programming Using Oracle 11g
Database Programming Using Oracle 11g
Presentation transcript:

Procedure Function Trigger

create table employee ( id number, name varchar2(100), deptno number, salary float, primary key(id) ) create table deptincrease ( deptno number, percentage number, primary key(deptno) ) EMPLOYEEidnamedeptnosalary DEPTINCREASEdeptnopercentage

EMPLOYEEidnamedeptnosalary DEPTINCREASEdeptnopercentage create or replace procedure raiseallsalary is cursor dept is select distinct deptno from deptincrease; deptval dept%ROWTYPE; dp number; begin for deptval in dept loop select percentage into dp from deptincrease where deptno=deptval.deptno; raisesalary(deptval.deptno,dp); end loop; end;

EMPLOYEEidnamedeptnosalary DEPTINCREASEdeptnopercentage create or replace procedure raisesalary(dept in number, percent in number) is cursor emp is select * from employee where deptno=dept; empval emp%ROWTYPE; newsalary float; begin open emp; loop fetch emp into empval; exit when emp%NOTFOUND; newsalary:=empval.salary + (empval.salary*percent)/100; update employee set salary=newsalary where id=empval.id; end loop; close emp; end;

EMPLOYEEidnamedeptnosalary DEPTINCREASEdeptnopercentage create or replace function getdeptsalary(dept number) return number is total number; begin total:= 0; for emp_sal in (select salary from employee where deptno = dept and salary is not null) loop total:= total + emp_sal.salary; end loop; return total; end;

EMPLOYEEidnamedeptnosalary DEPTINCREASEdeptnopercentage create or replace trigger eid_generate before insert on employee for each row declare cnt number; next number; begin select count(*) into cnt from employee; if cnt > 0 then select max(id) into next from employee; next:=next+1; :new.id:=next; else :new.id:=1; end if; end; Before insert or update After insert. :new :old