Database Programming with PL/SQL

Similar documents
Database Programming with PL/SQL

Using the Set Operators. Copyright 2006, Oracle. All rights reserved.


Actual4Test. Actual4test - actual test exam dumps-pass for IT exams

Database Programming with PL/SQL

Database Programming with SQL

Restricting and Sorting Data. Copyright 2004, Oracle. All rights reserved.

Introduction. Introduction to Oracle: SQL and PL/SQL

Restricting and Sorting Data. Copyright 2004, Oracle. All rights reserved.

Database Programming with SQL

Database Foundations. 6-1 Introduction to Oracle Application Express. Copyright 2015, Oracle and/or its affiliates. All rights reserved.

Database Programming with PL/SQL

Database Foundations. 6-4 Data Manipulation Language (DML) Copyright 2015, Oracle and/or its affiliates. All rights reserved.

Database Programming with PL/SQL

software.sci.utah.edu (Select Visitors)

Manipulating Data. Copyright 2004, Oracle. All rights reserved.

Database Programming with PL/SQL

Course Overview. Copyright 2010, Oracle and/or its affiliates. All rights reserved.

Database Programming with PL/SQL

Join, Sub queries and set operators

Oracle Database SQL Basics

Sample Test #1 Questions

Database Programming with PL/SQL

Cartesian Product and the Join Operations. Copyright 2008, Oracle. All rights reserved.

Department of Computer Science and Information Systems, College of Business and Technology, Morehead State University

Lab # 6. Data Manipulation Language (DML)

Contents I Introduction 1 Introduction to PL/SQL iii

Limit Rows Selected. Copyright 2008, Oracle. All rights reserved.

Oracle Development - Part III: Coding Standards

DBMS_OUTPUT.PUT_LINE('ERROR - max sal should be > MIN SAL'); RAISE sal_error;

PDA Database Programming in PL/SQL (Oracle PL/SQL Developer Certified Associate Certification Course)

Notes Lesson 3 4. Positive. Coordinate. lines in the plane can be written in standard form. Horizontal

SCI - software.sci.utah.edu (Select Visitors)

Database Programming with PL/SQL

Getting Information from a Table

Using the Set Operators. Copyright 2004, Oracle. All rights reserved.

INDEX. 1 Introduction. 2 Types of Cursors 2.1 Explicit cursor 2.2 Attributes 2.3 Implicit cursor 2.4 Attributes. 3 Parameterized cursor

Question No : 1 Which statement is true about triggers on data definition language (DDL) statements?

Database Programming - Section 18. Instructor Guide

DUE: 9. Create a query that will return the average order total for all Global Fast Foods orders from January 1, 2002, to December 21, 2002.

Database Programming with PL/SQL

Data Manipulation Language

ITDUMPS QUESTION & ANSWER. Accurate study guides, High passing rate! IT dumps provides update free of charge in one year!

Oracle PLSQL. Course Summary. Duration. Objectives

DATABASE DEVELOPMENT (H4)

Táblák tartalmának módosítása. Copyright 2004, Oracle. All rights reserved.

Introduction to Computer Science and Business

Oracle Database 10g: SQL Fundamentals I

Database Programming with SQL

1Z0-144 Q&As Oracle Database 11g: Program with PL/ SQL

Oracle Database 11g: PL/SQL Fundamentals

Introduction to Explicit Cursors. Copyright 2008, Oracle. All rights reserved.

Oracle 1Z Oracle Database 11g : SQL Fundamentals I. Download Full Version :

Introduction to Relational Database Concepts. Copyright 2011, Oracle. All rights reserved.

Section 1.2: What is a Function? y = 4x

Conversion Functions

Database Programming with SQL

Retrieving Data from Multiple Tables

Oracle Internal & Oracle Academy

Oracle Database 11g: SQL and PL/SQL Fundamentals

Informatics Practices (065) Sample Question Paper 1 Section A

Exam Name: Oracle Database 11g: Program with PL/SQL

School of Computing, Engineering and Information Sciences University of Northumbria. Set Operations

ADVALO TRAINING SCHEDULE FOR THE YEAR Exadata Database Machine: 12c Administration Workshop Ed 1

This report is based on sampled data. Jun 1 Jul 6 Aug 10 Sep 14 Oct 19 Nov 23 Dec 28 Feb 1 Mar 8 Apr 12 May 17 Ju

chapter 2 G ETTING I NFORMATION FROM A TABLE

Oracle Database 10g: PL/SQL Fundamentals

CS2 Current Technologies Lecture 2: SQL Programming Basics

Sisteme Informatice şi Standarde Deschise (SISD) Curs 7 Standarde pentru programarea bazelor de date (1)

CS2 Current Technologies Note 1 CS2Bh

Oracle Database: SQL Fundamentals I. Oracle Internal & Oracle Academy Use Only. Volume II Student Guide. D64258GC10 Edition 1.0 January 2010 D65028

MANAGING DATA(BASES) USING SQL (NON-PROCEDURAL SQL, X401.9)

Oracle Database: SQL and PL/SQL Fundamentals NEW

Creating and Managing Tables Schedule: Timing Topic

Oracle Database: SQL and PL/SQL Fundamentals Ed 2

GIFT Department of Computing Science Data Selection and Filtering using the SELECT Statement

1Z Oracle Database 11g - Program with PL/SQL Exam Summary Syllabus Questions

2 PL/SQL - fundamentals Variables and Constants Operators SQL in PL/SQL Control structures... 7

Lab # 6. Using Subqueries and Set Operators. Eng. Alaa O Shama

Vendor: Oracle. Exam Code: 1Z Exam Name: Oracle Database 11g: Program with PL/ SQL. Version: Demo

CS Reading Packet: "Views, and Simple Reports - Part 1"

Assertions, Views, and Programming. CS157A Chris Pollett Oct. 31, 2005.

Data Types. 9. Types. a collection of values and the definition of one or more operations that can be performed on those values

WHOIS Accuracy Reporting System (ARS): Phase 2 Cycle 1 Results Webinar 12 January ICANN GDD Operations NORC at the University of Chicago

SYSTEM CODE COURSE NAME DESCRIPTION SEM

Database Programming with SQL

Asks for clarification of whether a GOP must communicate to a TOP that a generator is in manual mode (no AVR) during start up or shut down.

DEFAULT Values, MERGE, and Multi-Table Inserts. Copyright 2009, Oracle. All rights reserved.

Getting in Gear with the Service Catalog

Michigan Tech University Banner Finance Self-Service User Guide. Revised 1/11/17

All King County Summary Report

Database Programming with SQL

Database Management System. * First install Mysql Database or Wamp Server which contains Mysql Databse.

Oracle 1Z Oracle Database 11g SQL Fundamentals I. Download Full Version :

chapter 12 C ONTROLLING THE LEVEL OF

RLMYPRINT.COM 30-DAY FREE NO-OBLIGATION TRIAL OF RANDOM LENGTHS MY PRINT.

Definition: Data Type A data type is a collection of values and the definition of one or more operations on those values.

Seattle (NWMLS Areas: 140, 380, 385, 390, 700, 701, 705, 710) Summary

OVERVIEW OF THE TYPES OF PL/SQL BLOCKS:

NCC Cable System Order

Transcription:

Database Programming with PL/SQL 1-1

Objectives This lesson covers the following objectives: Describe PL/SQL Differentiate between SQL and PL/SQL Explain the need for PL/SQL 3

Purpose PL/SQL is Oracle Corporation s procedural programming language for relational databases. To describe PL/SQL, you learn its characteristics and identify the differences between PL/SQL and SQL. Identifying limitations of SQL and how PL/SQL addresses those limitations will help you to understand why PL/SQL is needed. 4

PL/SQL Description Procedural Language extension to SQL. A third-generation programming language (3GL). An Oracle proprietary programming language. Combines program logic and control flow with SQL. 5

SQL Description A nonprocedural language. Also known as a "declarative language," allows programmer to focus on input and output rather than the program steps. A fourth-generation programming language (4GL). Primary language used to access and modify data in relational databases. Standardized by the American National Standards Institute (ANSI). Vendors such as Oracle typically include some proprietary SQL features in their database environments. 6

SQL Statement The SQL statement shown is simple and straightforward. However, if you need to modify a data item in a conditional manner, you come across a limitation of SQL. SELECT employee_id, job_id, hire_date FROM employees; For example, how would you write an SQL statement to update the job_id data with a new value determined by the current job_id and the hire_date? 7

Limitations of SQL Assume the company decides to promote all sales representatives, marketing representatives, and stock clerks employed for at least ten years to senior representatives and clerks. If the current date is 05-Feb-2015, sales representatives 174, 176, and 178 qualify for the promotion. EMPLOYEE_ID JOB_ID HIRE_DATE NEW JOB_ID 174 SA_REP 11-May-1996 SR_SA_REP 176 SA_REP 24-Mar-1998 SR_SA_REP 178 SA_REP 24-May-1999 SR_SA_REP 240 SA_REP 02-Oct-2005 242 SA_REP 09-Dec-2007 8

Limitations of SQL If the current date is 05-FEB-2015, stock clerks 141, 142, 143, and 144 also qualify for the promotion. EMPLOYEE_ID JOB_ID HIRE_DATE NEW JOB_ID 141 ST_CLERK 17-Oct-1995 SR_ST_CLERK 142 ST_CLERK 29-Jan-1997 SR_ST_CLERK 143 ST_CLERK 15-Mar-1998 SR_ST_CLERK 144 ST_CLERK 09-Jul-1998 SR_ST_CLERK 244 ST_CLERK 07-Sep-2009 9

Limitations of SQL One solution to updating the job_id data is shown. How many SQL statements do you need to write for sales representatives, marketing representatives, and stock clerks? What if there are other job_ids to update? UPDATE employees SET job_id = 'SR_SA_REP' WHERE job_id = 'SA_REP' AND hire_date <= '05-Feb-2005' UPDATE employees SET job_id = 'SR_ST_CLERK' WHERE job_id = 'ST_CLERK' AND hire_date <= '05-Feb-2005' and so on 10

Limitations of SQL You would need to write a separate SQL statement for each job_id that needs to be updated. Depending on the number of job_ids, this could be a tedious task. It would be easier to write a single statement to accomplish this task. The statement would require logic, otherwise known as procedural logic. PL/SQL extends SQL with procedural logic and makes it possible to write one statement to accomplish this task. 11

PL/SQL Extends SQL with Procedural Logic Using PL/SQL, you can write one statement to promote the sales representatives, marketing representatives, and stock clerks. DECLARE CURSOR c_employees IS SELECT * FROM employees; BEGIN FOR c_emp in c_employees LOOP IF c_emp.job_id = 'SA_REP' AND c_emp.hire_date <= '05-Feb-2005' THEN UPDATE employees SET job_id = 'SR_SA_REP' WHERE employee_id = c_emp.employee_id; ELSIF c_emp.job_id = 'MK_REP' AND c_emp.hire_date <= '05-Feb-2005' THEN UPDATE employees SET job_id = 'SR_MK_REP' WHERE employee_id = c_emp.employee_id; ELSIF c_emp.job_id = 'ST_CLERK' AND c_emp.hire_date <= '05-Feb-2005' THEN UPDATE employees SET job_id = 'SR_ST_CLRK' WHERE employee_id = c_emp.employee_id; END IF; END LOOP; END; 12

Procedural Constructs You use PL/SQL to write the procedural code and embed SQL statements within the PL/SQL code. The procedural code includes variables, constants, cursors, conditional logic, and iteration. PL/SQL code blocks can be saved and named, then executed whenever needed. 13

Procedural Constructs Highlighted Several PL/SQL constructs are highlighted below. Cursor DECLARE CURSOR c_employees IS SELECT * FROM employees; BEGIN FOR c_emp in c_employees LOOP IF c_emp.job_id = 'SA_REP' AND c_emp.hire_date <='05-Feb-2005' THEN UPDATE employees SET job_id = 'SR_SA_REP' WHERE employee_id = c_emp.employee_id; ELSIF c_emp.job_id = 'MK_REP' AND c_emp.hire_date <= '05-Feb-2005' Iterative Control END; THEN UPDATE employees SET job_id = 'SR_MK_REP' WHERE employee_id = c_emp.employee_id; ELSIF c_emp.job_id = 'ST_CLERK' AND c_emp.hire_date <='05-Feb-2005' THEN UPDATE employees SET job_id = 'SR_ST_CLRK' WHERE employee_id = c_emp.employee_id; END IF; END LOOP; SQL Conditional Control 14

Characteristics of PL/SQL PL/SQL: Is a highly structured, readable, and accessible language. Is a standard and portable language for Oracle development. Is an embedded language and it works with SQL. Is a high-performance, highly integrated database language. Is based on the Ada Programming Language and has many similarities in syntax. 15

Terminology Key terms used in this lesson included: PL/SQL Procedural Constructs 16

Summary In this lesson, you should have learned how to: Describe PL/SQL Differentiate between SQL and PL/SQL Explain the need for PL/SQL 17