您的位置:首页 > 其它

Chapter -09 Creating Procedures 00

2013-04-19 11:18 357 查看

Objectives

After competing this lesson,you should be able to do the following:

Identify the benefits of modualarized and layered subprogram design.

Create and call procedures.

Use formal and actual parameters

Use positional,named ,or mixed notation for passing parameters.

Identify the available parameter-passing modes.

Handle exceptions in procedures.

Remove a procedure

Display the prcedures`s information.

Lesson Agenda

Using a modularized and layered subprogram desing and identifying the benefits of subprograms.

Working with procedures

-Creating and calling procedures

-Identifying the available parameter-passing modes

-Using formal and actual parameters

-Using positional,named,or mixed notation

Handing execptions in procedures,removing a procedure,and displaying the procedures`s information.

Creating a Modularized Subprogram Desgin



Modularize code into subprograms.

1、Locate code sequences repeated more than onec.

2、Create subprogram P containing the repeated code.

3、Modify original code to invoke the new subprogram.

Creating a Layered Sumprogram Desgin

Create subprogram layers for you application.

Data access subprogram layer with SQL logic.

Business logic subprogram layer,which may or may not use the data access layer.



Modularizing Development with PL/SQL Blocks

PL/SQL is a block-structed language.The PL/SQL code block helps modularize code by using:

-Anonymous blocks

-Procedures and Functions

-Packages

-Database triggers

The benefits of using modular program constructs are:

-Easy maintenance

-Improved data security and integrity

-Improved performance

-Improved code clarity

Anonymous Blocks:Overview

Anonymous blocks:

Form the basic PL/SQL block structure

Initiate PL/SQL processing tasks from applications

Can be nested within the executable section of any PL/SQL block.

[DECLARE        -- Declarationg Section (Optional)
variable declarations;...]
BEGIN           --Executable Section(Mandatory)
SQL or PL/SQL statements;
[EXCEPTION      --Exception Section (Optional)
WHEN exception THEN statements;]
END;            --End of BLock(Mandatory)


PL/SQL Run-time Architecture



What Are PL/SQL Subprograms?

A PL/SQL subprogram is a named PL/SQL block that can be called with a set fo prameters.

You can declare and define a subprogram within either a PL/SQL block or another subprogram.

A subprogram consists of a specification and a body

A subprogram can be a procedure or a function.

Typically,you use a procedure to perform an action and a fuction to compute and return a value.

Subprograms can be grouped into PL/SQL packages.

The benefits of Using PL/SQL Subprograms



Differences Between Anonymous Blocks and Subprograms

Anonymous BlocksSubprograms
Unnamed PL/SQL blocksNamed PL/SQL blocks
Compiled every timeCompiled only once
Not stored in the databaseStored in the database
Cannot be invoked by other applicatonsNames and,therefore,can be invoked by other applicaitons
Do not return valuesSubprograms called functions must return values.
Cannot take parametersCan take parameters
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: