Oracle10g Developer: PL/SQL Programming1 Objectives SQL queries within PL/SQL Host or bind variables The %TYPE attribute Include queries and control structures.

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.
Chapter 8 Embedded SQL.
Chapter 4B: More Advanced PL/SQL Programming
Introduction to Structured Query Language (SQL)
1 Pertemuan 09 Database Matakuliah: D0524 / Algoritma dan Pemrograman Komputer Tahun: 2005 Versi:
Chapter 7 Advanced SQL Database Systems: Design, Implementation, and Management, Sixth Edition, Rob and Coronel.
A Guide to SQL, Seventh Edition. Objectives Embed SQL commands in PL/SQL programs Retrieve single rows using embedded SQL Update a table using embedded.
PL/SQL Bulk Collections in Oracle 9i and 10g Kent Crotty Burleson Consulting October 13, 2006.
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.
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:
PL/SQLPL/SQL Oracle10g Developer: PL/SQL Programming Chapter 11 Introduction to Dynamic SQL and Object Technology.
Chapter 7 Advanced SQL Database Systems: Design, Implementation, and Management, Sixth Edition, Rob and Coronel.
Oracle10g Developer: PL/SQL Programming1 Objectives Programming fundamentals The PL/SQL block Define and declare variables Initialize variables The NOT.
PL/SQLPL/SQL Oracle10g Developer: PL/SQL Programming Chapter 2 Basic PL/SQL Block Structures.
PL/SQLPL/SQL Oracle10g Developer: PL/SQL Programming Chapter 7 PL/SQL Packages.
PL/SQLPL/SQL Oracle10g Developer: PL/SQL Programming Chapter 6 Functions.
PL/SQLPL/SQL Oracle11g : PL/SQL Programming Chapter 6 Functions.
Using Special Operators (LIKE and IN)
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
CIS4368: Advanced DatabaseSlide # 1 PL/SQL Dr. Peeter KirsSpring, 2003 PL/SQL.
8 1 Chapter 8 Advanced SQL Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
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.
PL/SQLPL/SQL Oracle10g Developer: PL/SQL Programming Chapter 3 Handling Data in PL/SQL Blocks.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
1 DBS201: Introduction to Structure Query Language (SQL) Lecture 1.
SQL Basic. What is SQL? SQL (pronounced "ess-que-el") stands for Structured Query Language. SQL is used to communicate with a database.
Dynamic SQL Oracle Database PL/SQL 10g Programming Chapter 13.
Objectives Database triggers and syntax
PL/SQLPL/SQL Oracle10g Developer: PL/SQL Programming Chapter 9 Database Triggers.
SQL Jan 20,2014. DBMS Stores data as records, tables etc. Accepts data and stores that data for later use Uses query languages for searching, sorting,
Chapter 8 Advanced SQL Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
PL/SQLPL/SQL Oracle11g: PL/SQL Programming Chapter 4 Cursors and Exception Handling.
Chapter 4 An Introduction to SQL. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.4-2 Topics in this Chapter SQL: History and Overview The.
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.
A Guide to SQL, Eighth Edition Chapter Eight SQL Functions and Procedures.
PL/SQLPL/SQL Oracle11g: PL/SQL Programming Chapter 9 Database Triggers.
PL/SQLPL/SQL Oracle10g Developer: PL/SQL Programming Chapter 9 Database Triggers.
Retrieving Data in PL/SQL. 2 home back first prev next last What Will I Learn? In this lesson, you will learn to: –Recognize the SQL statements that can.
Oracle11g: PL/SQL Programming Chapter 3 Handling Data in PL/SQL Blocks.
implicit and an explicit cursor
CSCI 3328 Object Oriented Programming in C# Chapter 12: Databases and LINQ – Exercises 1 Xiang Lian The University of Texas Rio Grande Valley Edinburg,
Text TCS INTERNAL Oracle PL/SQL – Introduction. TCS INTERNAL PL SQL Introduction PLSQL means Procedural Language extension of SQL. PLSQL is a database.
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
1 Section 10 - Embedded SQL u Many computer languages allow you to embed SQL statements within the code (e.g. COBOL, PowerBuilder, C++, PL/SQL, etc.) u.
Oracle9i Developer: PL/SQL Programming Chapter 6 PL/SQL Packages.
Oracle 11g: SQL Chapter 5 Data Manipulation and Transaction Control.
6 Copyright © 2009, Oracle. All rights reserved. Using Dynamic SQL.
Chapter 4 An Introduction to SQL.
Chapter 2 Anonymous Block
A Guide to SQL, Seventh Edition
Oracle11g: PL/SQL Programming Chapter 1 Introduction to PL/SQL.
Interacting with the Oracle Server
Oracle11g: PL/SQL Programming Chapter 2 Basic PL/SQL Block Structures.
Oracle11g: PL/SQL Programming Chapter 4 Cursors and Exception Handling.
Oracle9i Developer: PL/SQL Programming Chapter 3 PL/SQL Processing.
Database Management Systems 2
Interacting with the Oracle Server
Chapter 2 Handling Data in PL/SQL Blocks Oracle9i Developer:
Chapter 10 Oracle9i Developer: PL/SQL Programming
Oracle9i Developer: PL/SQL Programming Chapter 8 Database Triggers.
Chapter 8 Advanced SQL.
Prof. Arfaoui. COM390 Chapter 9
Prof. Arfaoui. COM390 Chapter 6
Handling Data in PL/SQL Blocks
Prof. Arfaoui. COM390 Chapter 7
Presentation transcript:

Oracle10g Developer: PL/SQL Programming1 Objectives SQL queries within PL/SQL Host or bind variables The %TYPE attribute Include queries and control structures Embed DML statements within PL/SQL Composite data types Creating collections

Oracle10g Developer: PL/SQL Programming2 Brewbean’s Challenge Consider actions needed upon check out

Oracle10g Developer: PL/SQL Programming3 Include SQL within a Block Data query needs to identify if the customer has a saved basket

Oracle10g Developer: PL/SQL Programming4 SQL statements can be embedded into the executable area of a PL/SQL block SELECT statements are embedded to query needed data An INTO clause is added to a SELECT statement to move data retrieved into variables Include SQL within a Block

Oracle10g Developer: PL/SQL Programming5 SQL Query – add INTO clause Assignment Statement Include SQL within a Block

Oracle10g Developer: PL/SQL Programming6 Executing a Block with Errors Common Errors – Use = rather than := – Not declaring a variable – Misspelling a variable name – Not ending a statement with ; – No data returned from a SELECT statement

Oracle10g Developer: PL/SQL Programming7 Not closing a statement with ; Executing a Block with Errors

Oracle10g Developer: PL/SQL Programming8 Host or Bind Variables Reference host variables with a preceding colon in PL/SQL BEGIN :g_shopper := 25; END; / WHERE idShopper = :g_shopper AND orderplaced = 0; Create host variable Reference host variable

Oracle10g Developer: PL/SQL Programming9 %TYPE Attribute Use in variable declaration to provide data type based on a table column Ideal for declaring variables that will hold data from the database Minimizes maintenance by avoiding program changes to reflect database column changes Called an anchored data type lv_basket_num bb_basket.idBasket%TYPE;

Oracle10g Developer: PL/SQL Programming10 Data Retrieval & Decisions

Oracle10g Developer: PL/SQL Programming11 IF Statement Example

Oracle10g Developer: PL/SQL Programming12 Including DML DML statements can be embedded into PL/SQL blocks to accomplish data changes DML includes INSERT, UPDATE, and DELETE statements

Oracle10g Developer: PL/SQL Programming13 Including DML Add a new shopper - INSERT

Oracle10g Developer: PL/SQL Programming14 Composite Data Types Stores multiple values of different data types as one unit Record – can hold one row of data Table of records – can hold multiple rows of data

Oracle10g Developer: PL/SQL Programming15 Record Data Type DECLARE TYPE type_basket IS RECORD ( basket bb_basket.idBasket%TYPE, created bb_basket.dtcreated%TYPE, qty bb_basket.quantity%TYPE, sub bb_basket.subtotal%TYPE); rec_basket type_basket; lv_days_num NUMBER(3); lv_shopper_num NUMBER(3) := 25; BEGIN SELECT idBasket, dtcreated, quantity, subtotal INTO rec_basket FROM bb_basket WHERE idShopper = lv_shopper_num AND orderplaced = 0; lv_days_num := SYSDATE - rec_basket.created; END;

Oracle10g Developer: PL/SQL Programming16 %ROWTYPE Attribute Create record structure based on table structure DECLARE rec_shopper bb_shopper%ROWTYPE; BEGIN SELECT * INTO rec_shopper FROM bb_shopper WHERE idshopper = :g_shopper; DBMS_OUTPUT.PUT_LINE(rec_shopper.lastname); DBMS_OUTPUT.PUT_LINE(rec_shopper.address); DBMS_OUTPUT.PUT_LINE(rec_shopper. ); END;

Oracle10g Developer: PL/SQL Programming17 Table of Records

Oracle10g Developer: PL/SQL Programming18 Collections Store multiple values of the same data type Similar to arrays in other languages Index-by Tables – handle many rows of one field One- dimensional Can only have one column UnconstrainedRows added dynamically as needed SparseA row only exists when a value is assigned; rows do not have to be assigned sequentially HomogeneousAll elements have same data type IndexedInteger index serves as primary key of the table

Oracle10g Developer: PL/SQL Programming19 Index-by Table Attributes Attribute Name Value Data typeDescription COUNTNUMBERNumber of rows in the table DELET E NoneRemoves a row from the table EXISTSBOOLEANTRUE if specified row does exist FIRSTBINARY_INTEG ER Index for the first row in the table LASTBINARY_INTEG ER Index for the last row in the table NEXTBINARY_INTEG ER Index for the next row in the table after the row specified PRIORBINARY_INTEG ER Index for the row in the table before the row specified

Oracle10g Developer: PL/SQL Programming20 Index-by Table Example Host variables declaration and initialization

Oracle10g Developer: PL/SQL Programming21 Index-by Table Example Put host variable values into the table variable A FOR loop adds all the sample measurements that have been entered into the table variable lv_avg_num calculates the Average measurement Index-by table data type declaration Index-by table variable declaration

Oracle10g Developer: PL/SQL Programming22 Summary SQL queries and DML statements can be embedded into a block An INTO clause must be added to a SELECT The %TYPE attribute is used to use a column data type Composite data types can hold multiple values in a single variable

Oracle10g Developer: PL/SQL Programming23 Summary A record can hold a row of data A table of records can hold multiple rows of data The %ROWTYPE attribute can be used to declare a data type based on a table’s structure An index-by table is a collection similar to arrays The GOTO statement enables execution to jump to specific portions of code