Oracle11g: PL/SQL Programming Chapter 3 Handling Data in PL/SQL Blocks.

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.
Oracle11g: PL/SQL Programming Chapter 1 Introduction to PL/SQL.
Guide to Oracle10G1 Introduction To Forms Builder Chapter 5.
Chapter 4B: More Advanced PL/SQL Programming
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.
Introduction to PL/SQL Lecture 0 – Self Study Akhtar Ali.
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:
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.
PL/SQLPL/SQL Oracle10g Developer: PL/SQL Programming Chapter 11 Introduction to Dynamic SQL and Object Technology.
Database Security and Auditing: Protecting Data Integrity and Accessibility Chapter 6 Virtual Private Databases.
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.
PL/SQLPL/SQL Oracle10g Developer: PL/SQL Programming Chapter 1 Introduction to PL/SQL.
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.
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.
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.
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 9: Advanced SQL and PL/SQL Guide to Oracle 10g.
Chapter 16 Cursors and Exceptions. Chapter Objectives  Determine when an explicit cursor is required  Declare, open, and close an explicit cursor 
Chapter Fourteen Access Databases and SQL Programming with Microsoft Visual Basic th Edition.
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.
Oracle10g Developer: PL/SQL Programming1 Objectives SQL queries within PL/SQL Host or bind variables The %TYPE attribute Include queries and control structures.
Introduction to Explicit Cursors. 2 home back first prev next last What Will I Learn? Distinguish between an implicit and an explicit cursor Describe.
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.
PL/SQLPL/SQL Oracle10g Developer: PL/SQL Programming Chapter 8 Program Unit Dependencies.
PL/SQLPL/SQL Oracle11g: PL/SQL Programming Chapter 10 Oracle-Supplied Packages, Dynamic SQL, and Hiding Source Code.
implicit and an explicit cursor
A Guide to SQL, Eighth Edition Chapter Six Updating Data.
Chapter 6 Virtual Private Databases
Text TCS INTERNAL Oracle PL/SQL – Introduction. TCS INTERNAL PL SQL Introduction PLSQL means Procedural Language extension of SQL. PLSQL is a database.
Program with PL/SQL Lesson 3. Interacting with the Oracle Server.
Oracle9i Developer: PL/SQL Programming Chapter 5 Functions.
Oracle9i Developer: PL/SQL Programming Chapter 6 PL/SQL Packages.
6 Copyright © 2009, Oracle. All rights reserved. Using Dynamic SQL.
Chapter 2 Anonymous Block
A Guide to SQL, Seventh Edition
Oracle11g: PL/SQL Programming Chapter 5 Procedures.
Chapter 8 Dependencies, Privileges and Compilation Oracle11g:
Oracle11g: PL/SQL Programming Chapter 1 Introduction to PL/SQL.
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.
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:

Oracle11g: PL/SQL Programming Chapter 3 Handling Data in PL/SQL Blocks

Chapter Objectives After completing this lesson, you should be able to understand: SQL queries in PL/SQL The %TYPE attribute Expanding block processing to include queries and control structures Embedding DML statements in PL/SQL Oracle11g: PL/SQL Programming

Chapter Objectives (continued) After completing this lesson, you should be able to understand (continued): Using record variables Creating collections Bulk processing basics GOTO statement Oracle11g: PL/SQL Programming

Brewbean’s Challenge Consider actions needed upon check out Oracle11g: PL/SQL Programming

Include SQL within a Block Data query needs to identify if the customer has a saved basket Oracle11g: PL/SQL Programming

Include SQL within a Block (continued) 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 Oracle11g: PL/SQL Programming

Include SQL within a Block (continued) Query – add INTO clause Assignment Statement Oracle11g: PL/SQL Programming

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 Oracle11g: PL/SQL Programming

Executing a Block with Errors (continued) Not closing a statement with ; Oracle11g: PL/SQL Programming

%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; Oracle11g: PL/SQL Programming

Data Retrieval with Decision Structures Oracle11g: PL/SQL Programming

IF Statement Example Oracle11g: PL/SQL Programming

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

Including DML (continued) Add a new shopper - INSERT Oracle11g: PL/SQL Programming

Record variables Stores multiple values of different data types as one unit Record – can hold one row of data Oracle11g: PL/SQL Programming

Record Data Type Oracle11g: PL/SQL Programming

%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 = 25; DBMS_OUTPUT.PUT_LINE(rec_shopper.lastname); DBMS_OUTPUT.PUT_LINE(rec_shopper.address); DBMS_OUTPUT.PUT_LINE(rec_shopper.email); END; Oracle11g: PL/SQL Programming

INSERT Using Record Oracle11g: PL/SQL Programming

Collections Store multiple values of the same data type Similar to arrays in other languages Associative Array– handle many rows of one field Oracle11g: PL/SQL Programming

Associative Array Attributes Oracle11g: PL/SQL Programming

Associative Array Example Oracle11g: PL/SQL Programming

Example (continued) Oracle11g: PL/SQL Programming

Table of Records Contains one or more records Handle shopping basket data Oracle11g: PL/SQL Programming

Table of Records Oracle11g: PL/SQL Programming

Bulk Processing Improve performance & add capabilities Reduces context switching Groups SQL actions for processing BULK COLLECT and FORALL statements More examples in Chapter 4 Oracle11g: PL/SQL Programming

Bulk Processing Enables loading multi-row query directly to table of record variable Oracle11g: PL/SQL Programming

GOTO Statement Jumping control that instructs the program to move to another area of code to continue processing Most developers discourage the use of GOTO as it complicates the flow of execution Oracle11g: PL/SQL Programming

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 A record can hold a row of data A table of records can hold multiple rows of data Oracle11g: PL/SQL Programming

Summary (continued) The %ROWTYPE attribute can be used to declare a data type based on a table’s structure An associative array is a collection of same type data Bulk processing groups SQL statements for processing to improve performance The GOTO statement enables execution to jump to specific portions of code Oracle11g: PL/SQL Programming