Lecture Seventeen

 

PL/SQL

 

Learning Objectives

 

·         To illustrate the features and benefits of PL/SQL.

·         To introduce the PL/SQL program constructs.

 

 

 

 


Introduction

 

 

Benefits of PL/SQL

 

PL/SQL Engine

 

PL/SQL block

 

PL/SQL Program Constructs

 

Anonymous Block

 

Stored Procedure Or Function

 

Application Procedure Or Function

 

Package

 

Triggers

 

Application Trigger

 

Syntax Rules

 

Summary

 

 

Review Questions

 

1. What are the benefits of accessing the database with PL/SQL?

2. What are the advantages of using pl/sql to access the database over using other programming languages for database access?

3. Identify the three parts of a PL/SQL block: declaration, execution, and exception handler.

4. What are the syntactic and semantic differences between named and anonymous blocks?

 

 

Answer:

4. The most important difference to remember is that named blocks are stored in Oracle as compiled code and can be referenced with a procedure or function call either from other pl/sql blocks or from the SQL*Plus command line. Anonymous blocks must be parsed and executed every time they are run, and they are usually stored in flat files called from SQL*Plus.

 

 

Practice Test

 

1. You develop a PL/SQL named program and compile it. Your PL/SQL program is now stored in which of the following areas?

A. In an executable program         B. In a flat file          C. In the Oracle database      D. In SQL*Plus

 

2. You are using PL/SQL to support code centralization in your organization. Which of the following choices does not identify a feature offered by PL/SQL's centralization?

A. More manageable upgrade process

B. Program that takes advantage of client PC power

C. Single copy of program available for all users

D. Native communication with the database

 

3. You want to use the feature in PL/SQL that allows different versions of the same procedure to accept information of different datatypes. Which of the following terms best describes this feature?

A. Encapsulation                 B. Packages              C. Modularization                   D. Overloading

 

4. Use the following code block to answer this question:

SQL> create or replace package my_pkg is

2   /*********/

3    function f_no_op

4    ( myvar in number)

5    return number;

6 /********/

7    procedure no_op

8    ( myvar in number) ;

9 end;

10 /

Package created.

 

Which of the following choices identifies the type of code block shown here?

A. Package specification                 

B. Package body

C. Procedure specification

D. Procedure body

 

5. You are creating a function in PL/SQL. Which two of the following components must appear in every function in PL/SQL (without them, Oracle returns an error)?

A. Declared variables

B. A return statement

C. A begin-end section

D. An exception section

 

6. You are developing PL/SQL programs. Which of the following choices best describes a possible definition for a trigger?

A. A code block containing procedure and function specifications that has an associated body containing the actual code

B. A code block containing procedure and function bodies that has an associated specification containing the procedure and function definitions

C. A code block associated with a table that Oracle executes whenever a specified event occurs

D. An unnamed code block parsed and executed at the same time

 

 

 

 

 

Answer

1.C.      2. B.           3-D.             4. A.       5. B and C.   6. C.

 

 

 

Assignment

 

 

Required Readings

Textbook:   

                  Chapter 7 “PL/SQL Basics"  

Chip Dawes and Biju Thomas 
Oracle DBA and PL/SQL Study Guide 
Sybex. 
ISBN 0-7821-2682-0.