Database Programming Using Oracle 11g

Slides:



Advertisements
Similar presentations
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.
Advertisements

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.
Library example CREATE TABLE books ( isbn VARCHAR2(13) PRIMARY KEY, title VARCHAR2(200), summary VARCHAR2(2000), author VARCHAR2(200), date_published DATE,
PL/SQL Agenda: Basic PL/SQL block structure
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)
Introduction to PL/SQL. Procedural Language extension for SQL Oracle Proprietary 3GL Capabilities Integration of SQL Portable within Oracle data bases.
PL / SQL P rocedural L anguage / S tructured Q uery L anguage Chapter 7 in Lab Reference.
Agenda Journalling More Embedded SQL. Journalling.
SAGE Computing Services Customised Oracle Training Workshops and Consulting Are you making the most of PL/SQL? Hints and tricks and things you may have.
Stored Procedures Functions Packages
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.
6 Copyright © 2009, Oracle. All rights reserved. Working with Composite Data Types.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
INTRODUCTION TO PL/SQL. Class Agenda Introduction Introduction to PL/SQL Declaring PL/SQL Variable Creating the Executable Section Interacting with the.
Stored procedures1 Stored procedures and functions Procedures and functions stored in the database.
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.
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.
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.
8 1 Chapter 8 Advanced SQL Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
BIS Database Systems School of Management, Business Information Systems, Assumption University A.Thanop Somprasong Chapter # 8 Advanced SQL.
PL/SQL Block Structure DECLARE - Optional Variables, cursors, user-defined exceptions BEGIN - Mandatory SQL Statements PL/SQL Statements EXCEPTIONS - Optional.
Oracle 8i PL/SQL Collections. Collections A Collection is a group of elements of the same kind There are three types of Collections that you can use in.
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;
Collections Oracle Database PL/SQL 10g Programming Chapter 6.
PL/SQLPL/SQL Oracle10g Developer: PL/SQL Programming Chapter 3 Handling Data in PL/SQL Blocks.
School of Computing and Management Sciences © Sheffield Hallam University SQL is non-procedural –designed to be relatively approachable to non- programmers.
Copyright  Oracle Corporation, All rights reserved. 18 Interacting with the Oracle Server.
ITEC 224 Database Programming PL/SQL Lab Cursors.
1 Writing Control Structures Part D. 2 PL/SQL Decision Control Structures Sequential processing Sequential processing Processes statements one after another.
Oracle10g Developer: PL/SQL Programming1 Objectives SQL queries within PL/SQL Host or bind variables The %TYPE attribute Include queries and control structures.
implicit and an explicit cursor
Advanced Databases More Advanced PL/SQL Programing 1.
Program with PL/SQL Lesson 3. Interacting with the Oracle Server.
Copyright  Oracle Corporation, All rights reserved. 20 Working with Composite Datatypes.
6 Copyright © 2004, Oracle. All rights reserved. Working with Composite Data Types.
Oracle 9i Collections. Composite types Several variables as single unit ◦ Records  Different datatype variables are combined here  Ex: All fields of.
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.
CS422 Principles of Database Systems Oracle PL/SQL Chengyu Sun California State University, Los Angeles.
6 Copyright © 2009, Oracle. All rights reserved. Using Dynamic SQL.
7 Copyright © 2004, Oracle. All rights reserved. Using Explicit Cursors.
Web Database Programming Using PHP
CS322: Database Systems PL/ SQL PL/SQL by Ivan Bayross.
Pl/SQL LANGUAGE MULITPLE CHOICE QUESTION SET-3
Indexing Goals: Store large files Support multiple search keys
Creating Stored Procedures and Functions
PL/SQL LANGUAGE MULITPLE CHOICE QUESTION SET-1
Web Database Programming Using PHP
Collection in PL/SQL.
PL/SQL MULTIPLE CHOICE QUESTION.
SQL PL/SQL Presented by: Dr. Samir Tartir
Interacting with the Oracle Server
كتابة الجمل التنفيذية في PL/SQL
Working with Composite Datatypes
Arrays An Array is an ordered collection of variables
Chapter 2 Handling Data in PL/SQL Blocks Oracle9i Developer:
PL/SQL week10.
PL/SQL Declaring Variables.
Handling Data in PL/SQL Blocks
Database Programming Using Oracle 11g
Database Programming Using Oracle 11g
Database Programming Using Oracle 11g
Presentation transcript:

Database Programming Using Oracle 11g Collection

Collection Collection Similar to Arrays with some difference. Collection can hold multiple data of similar datatype. Data is accessed through index. Size of collection is dynamic. Indexes are can be random

Collection PL/SQL Tables or Associated Array Associate Array is a pair of key / value pair Key is string or integer index. Value is accessed through key Key is unique

Collection PL/SQL Tables or Associated Array Index can be or can’t be sequential Size is dynamic or with very high limit Index can be sparse or dense Index can be number or string

Collection Syntax of PL/SQL Tables

Records Step-1: TYPE table_type_name IS TABLE OF datatype [NOT NULL] INDEX BY BINARY_INTEGER; Binary_integer: It store less than number Range: -2147483647 to 2147483647 Step-2: Variable of type Table_type_name

Collection Syntax of PL/SQL Tables Value of PL/SQL Table is accessed : PL/SQL Table name (i) i:=Index.

Collection Implementing PL/SQL Tables -I

Records DECLARE TYPE JobTabTyp IS TABLE OF emp.ename%type INDEX BY BINARY_INTEGER; job_tab JobTabTyp; -- declare local PL/SQL table job_title emp.job%TYPE; designation varchar2(16):='Prog'; counter number(10):=0; BEGIN

Records loop job_tab(counter) :=designation; dbms_output.put_line (job_tab(counter)); counter:=counter+1; exit when counter >100; end loop; END;

Collection PL/SQL Tables and Attributes Attributes are available with PL/SQL tables which make them easy to use. There are 7 attributes

Collection PL/SQL Tables and Attributes Attributes are available with PL/SQL tables which make them easy to use. There are 7 attributes Some need parameters Some act like procedure like delete

Collection Syntax of using PL/SQL Table with attributes

Records plsql_table_name{ . FIRST | . NEXT | . DELETE[(index[, index])] . EXISTS(index) | . COUNT | . NEXT(index) | . PRIOR(index)}

Collection PL/SQL Tables and Attributes Any or no attribute can be used with PL/SQL tables

Collection PL/SQL Table and First and Next Attribute First return first index number in the PL/SQL table Last attribute return index last number of the PL/SQL table. Parameter is required in next attribute

Collection PL/SQL Table and Count Attribute Count is a numeric attribute which return total number of index created. Useful because index are not sequential by default.

Collection PL/SQL Table and Exist Attribute Index of the PL/SQL table can be dense or sparse Exists return true if there is value on the particular index otherwise it will return false

Collection PL/SQL Table and Delete Attribute It can delete particular entry from PL/SQL table Can be used with name of PL/SQL table

Collection Implementing PL/SQL Table -II

Collection DECLARE cursor c1 is select ename from emp where sal <3000; type c2 is table of emp.ename%type index by binary_integer; c3 c2; counter number(10):=0; begin

Collection for i in c1 loop counter :=counter+2; c3(counter):=i.ename; dbms_output.put_line (c3(counter)); end loop; end;

Collection Implementing PL/SQL Table -III

Collection DECLARE cursor c1 is select ename from emp; type c2 is table of emp.ename%type index by binary_integer; c3 c2; counter number(10):=0; b number(10):=0; begin for i in c1 loop counter :=counter+2;

Collection c3(counter):=i.ename; --dbms_output.put_line (c3(counter)); end loop; dbms_output.put_line ('Value of counter : ' || counter); dbms_output.put_line (c3.count()); while (b<counter) loop if c3.exists(b) then

Collection dbms_output.put_line ('Value exists at Index : '|| b); end if ; b:=b+1; end loop; end;

Collection Implementing PL/SQL Table -IV

Collection Write a PL/SQL block to load all the Employee names into PL/SQL Table and copy the values in another PL/SQL Table before deleting those values from first PL/SQL Table

Collection DECLARE cursor c1 is select ename from emp; type c2 is table of emp.ename%type index by binary_integer; c3 c2; c4 c2; counter number(10):=0; b number(10):=0; begin for i in c1 loop counter :=counter+2;

Collection c3(counter):=i.ename; --dbms_output.put_line (c3(counter)); end loop; dbms_output.put_line ('Value of counter : ' || counter); dbms_output.put_line (c3.count()); while (b<counter) loop if c3.exists(b) then dbms_output.put_line ('Value exists at Index : '|| b);

Collection c4(b):=c3(b); c3.delete(b); dbms_output.put_line ('Value is deleted at Index '|| b); dbms_output.put_line ('Value copied in new PL/SQL Table '|| c4(b)); end if ; b:=b+1; end loop; end;

Collection Implementing PL/SQL Table and SQL-I

Collection Write a PL/SQL block to load all the Employee names into PL/SQL Table and insert the values into another table along with employee number and currentdate

Collection DECLARE cursor c1 is select ename from emp; type c2 is table of emp.ename%type index by binary_integer; c3 c2; c4 c2; counter number(10):=0; b number(10):=0; begin for i in c1 loop

Collection counter :=counter+2; c3(counter):=i.ename; --dbms_output.put_line (c3(counter)); end loop; dbms_output.put_line ('Value of counter : ' || counter); dbms_output.put_line (c3.count()); while (b<counter) loop if c3.exists (b) then

Collection insert into history values (b,c3(b),sysdate()); dbms_output.put_line ('Row is inserted using PL/SQL Table'); end if ; b:=b+1; end loop; end;