Cursor. Cursors Operations Cursors adalah suatu nama area yang berisi hasil dari suatu statement SQL. 1. OPEN 2. FETCH 3. CLOSE.

Slides:



Advertisements
Similar presentations
Definition Cursor is a control structure for the successive traversal of records in a result set. Cursor is a record pointer in a database. DATABASE CURSOR.
Advertisements

8 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Using Explicit Cursors.
PL/SQL.
SQL*PLUS, PLSQL and SQLLDR Ali Obaidi. SQL Advantages High level – Builds on relational algebra and calculus – Powerful operations – Enables automatic.
Murali Mani Persistent Stored Modules (Stored Procedures) : PSM.
Cursors How to step through the returned set of rows.
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.
Programming in Oracle with PL/SQL
Exception Handling in PL/SQL. POINTS TO DISCUSS What is Exception Handling Structure of Exception Handling Section Types of Exceptions.
2 Copyright © 2004, Oracle. All rights reserved. Creating Stored Functions.
9 Copyright © 2009, Oracle. All rights reserved. Introducing Stored Procedures and Functions.
Copyright  Oracle Corporation, All rights reserved. 4 Creating Functions.
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)
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.
Programming in Oracle with PL/SQL ProceduralLanguageExtension toSQL.
Distributed Database Applications COSC 5050 Week Three.
PL / SQL P rocedural L anguage / S tructured Q uery L anguage Chapter 7 in Lab Reference.
Copyright  Oracle Corporation, All rights reserved. 3 Creating Procedures.
EE Copyright س Oracle Corporation, All rights reserved. ® Review of PL/SQL.
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.
PL/SQL CSE2132 Database Systems Week 9 Lecture PL/SQL and Programming in Oracle - 2.
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.
PL/SQL A BRIEF OVERVIEW DAVID WILSON. PL/SQL User’s Guide and Reference PL/SQL User’s Guide and Reference.
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.
L/O/G/O Working with Composite Data Types. Objectives After completing this lesson, you should be able to do the following: –Create user-defined PL/SQL.
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.
PL/SQL Procedural Language / Structured Query Language.
8 1 Chapter 8 Advanced SQL Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
PL/SQL Block Structure DECLARE - Optional Variables, cursors, user-defined exceptions BEGIN - Mandatory SQL Statements PL/SQL Statements EXCEPTIONS - Optional.
PL/SQL Declaring Variables PL/SQL Block Structure DECLARE (Optional) Variables, cursors, user-defined exceptions BEGIN (Mandatory) - SQL statements -
Trigger Oracle PL/SQL. Triggers Associated with a particular table Associated with a particular table Automatically executed when a particular event occurs.
PL/SQL. Introduction to PL/SQL block Declare declarations Begin executable statement Exception exception handlers End;
Database Application Development using PL/SQL Programming.
Database Management COP4540, SCS, FIU Oracle PL/SQL (Ch 10.5)
School of Computing and Management Sciences © Sheffield Hallam University SQL is non-procedural –designed to be relatively approachable to non- programmers.
Using SQL in PL/SQL ITEC 224 Database Programming.
Chapter Sixteen Cursors Objective: – Introduction to cursors – Use of cursors in a database record – Implicit & explicit cursors – Cursors & loops – Cursors.
ITEC 224 Database Programming PL/SQL Lab Cursors.
Chapter 16 Cursors and Exceptions. Chapter Objectives  Determine when an explicit cursor is required  Declare, open, and close an explicit cursor 
Cursors For viewing and updating. Cursors How to step through the returned set of rows.
implicit and an explicit cursor
Creating Functions. V 12 NE - Oracle 2006 Overview of Stored Functions A function is a named PL/SQL block that returns a value A function can be stored.
PL/SQL programming Procedures and Cursors Lecture 1 [Part 2]
Creating Procedures. PL/SQL Program Construct Tools Constructs Anonymous Block Application procedures or functions Application packages Application Triggers.
Program with PL/SQL Lesson 3. Interacting with the Oracle Server.
PL/SQL  PL/SQL stands for Procedural Language/SQL.  PL/SQL extends SQL by adding constructs found in procedural languages like procedures, loops, variables,
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.
9 Copyright © 2007, Oracle. All rights reserved. Creating Stored Procedures and Functions.
1 Copyright © 2004, Oracle. All rights reserved. PL/SQL Programming Concepts: Review.
7 Copyright © 2004, Oracle. All rights reserved. Using Explicit Cursors.
ITEC 224 Database Programming
Creating Stored Procedures and Functions
Oracle11g: PL/SQL Programming Chapter 4 Cursors and Exception Handling.
Cursors ITEC 224 Database Programming PL/SQL Lab.
Handling Exceptions.
Chapter Eighteen Cursors
Interacting with the Oracle Server
Oracle Stored Procedures and Functions
Database Management Systems 2
Database Management Systems 2
Cursors.
PL/SQL Declaring Variables.
Presentation transcript:

Cursor

Cursors Operations Cursors adalah suatu nama area yang berisi hasil dari suatu statement SQL. 1. OPEN 2. FETCH 3. CLOSE

Cursors Attribute 1. %FOUND 2. %NOTFOUND 3. %ROWCOUNT 4. %ISOPEN

Function & Procedure

Function FUNCTION Nama_Function (parameter) RETURN TYPE IS deklarasi variabel BEGIN statement; RETURN(variable/value); END;

Procedure PROCEDURE Nama_Procedure (parameter) IS deklarasi variabel BEGIN statement; EXCEPTION statement; END;

Parameter Syntax parameter_name [IN | OUT | IN OUT] datatype [:= expr]

Procedure Parameter Modes Procedure IN OUT Argumen (DECLARE) BEGIN END; EXCEPTION Calling Environment IN Argument OUT Argument

Function Parameter Modes Function (DECLARE) BEGIN END; EXCEPTION Calling Environment IN Argument

Procedure vs Function ProcedureFunction Execute as a PL/SQL statement Called as part of an expression No RETURN datatypeMust contain a RETURN datatype Can return a valueMust return a value

Example DECLARE v_tax number; v_sal emp.salary%TYPE; BEGIN SELECT salary into v_sal FROM emp WHERE id = 97001; v_tax := Tax(v_sal); EXCEPTION WHEN NO_DATA_FOUND THEN v_tax := 0; END; FUNCTION Tax(v_value IN NUMBER) RETURN NUMBER IS BEGIN RETURN(v_value *.07); END Tax;

Example DECLARE v_idemp.id%TYPE := 97001; v_salemp.salary%TYPE; BEGIN SELECT salary into v_sal FROM emp WHERE id = v_id; Change_Salary(v_id, v_sal*1.1); EXCEPTION WHEN NO_DATA_FOUND THEN NULL; END; PROCEDURE Change_Salary (v_emp_id IN NUMBER, v_new_salary IN NUMBER) IS BEGIN UPDATE s_emp SET salary = v_new_salary WHERE id = v_emp_id; COMMIT; END Change_Salary;