Tài liệu modularizing programming with subprograms pdf

34 445 0
Tài liệu modularizing programming with subprograms pdf

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

20 Modularizing Programming with Subprograms Schedule: Timing Topic 60 minutes 20 minutes 80 minutes Lecture Practice Total Class Management Note: Files required for lesson are: DEMO: l20proc.pls, l20func.pls PRACTICE: p20proc.pls 20Ć2 Introduction to Oracle: SQL and PL/SQL Using Procedure Builder Objectives Modularity allows you to break your code into manageable, well-defined logical units Each of these units in PL/SQL is called a program unit, or a subprogram PL/SQL has two types of subprograms called procedures and functions This lesson covers the structure of subprograms and how to invoke them At the end of this lesson, you should be able to D Determine the types of program units and where to use them D Explain the differences between and benefits of procedures and functions D Develop subprograms D Invoke subprograms from Procedure Builder Class Management Note: This lesson is designed to give students an overview of a subprogram because Procedure Builder can only store subprograms, not anonymous blocks Therefore, use this lesson as a high level overview, with the details to follow in the next lessons Modularizing Programming with Subprograms 20Ć3 20Ć4 Introduction to Oracle: SQL and PL/SQL Using Procedure Builder Overview Program units are named PL/SQL blocks They fall into three main categories: D Procedures to perform actions D Functions to compute a value D Packages to bundle logically related procedures and functions Stored or Application Subprogram? These program units can be created in a variety of environments, including server-side stored subprograms or as application subprograms Concept Stored Subprogram Application Subprogram Location Is in the database Is within the application Executed From any database tool or application From only the application in which it was created Availability By way of database security Independently of, and in addition to, stored subprograms Subprograms are composed of a number of sections: D A header to name and type the block D An optional declarative section to set up local identifiers D An executable part to perform the actions D An optional exception handling section to handle exceptions For more information, see PL/SQL User’s Guide and Reference, Release 2.3, “Subprograms.” Class Management Note: Packages and other PL/SQL constructs are covered in the Develop Database Procedures course Modularizing Programming with Subprograms 20Ć5 20Ć6 Introduction to Oracle: SQL and PL/SQL Using Procedure Builder Creating a Subprogram The following steps will assist you to create a subprogram Select your environment If using Procedure Builder, then select either the Program Units node or the Database Objects node and Stored Procedures Units subobject node Write your syntax If using Procedure Builder, enter the syntax in the Program Unit Editor If using SQL*Plus, write your code in a text editor as a script file Compile your code The source code is complied into p-code If using Procedure Builder, click the Compile button If using SQL*Plus, start your file at the SQL prompt Invoke the successfully compiled procedure or function Guidelines D SQL*Plus is another development environment for writing and for initial testing of a procedure, although you will need to test the procedure by invoking it from an application D The SQL commands issued to create a stored subprogram are CREATE PROCEDURE or CREATE FUNCTION D The SQL commands issued to remove a stored subprogram are DROP PROCEDURE or DROP FUNCTION D Use CREATE OR REPLACE PROCEDURE or CREATE OR REPLACE FUNCTION so you not have to issue a DROP statement Modularizing Programming with Subprograms 20Ć7 20Ć8 Introduction to Oracle: SQL and PL/SQL Using Procedure Builder Creating a Procedure Create a PL/SQL procedure to store a series of actions for later execution The procedure can contain zero or more parameters, which are arguments that you list when calling the procedure Syntax PROCEDURE name [(parameter, )] IS pl/sql_block; where: name is the procedure name, which adheres to the standard Oracle naming rules parameter is the parameter syntax shown below pl/sql_block is the procedural body that defines the action performed by the procedure The parameter syntax is as follows Syntax parameter_name [IN | OUT | IN OUT] datatype [{:= | DEFAULT} expr] where: parameter_name is the name of the parameter datatype is the datatype of the parameter, without constraints expr is the value to initialize the parameter Guidelines D Start the PL/SQL block with the keyword IS D Enter any local declarations between IS and BEGIN When creating the procedure from Procedure Builder, the CREATE OR REPLACE portion of the syntax is implied Therefore, when creating the procedure from SQL*Plus, begin the statement with CREATE OR REPLACE Modularizing Programming with Subprograms 20Ć9 20Ć10 Introduction to Oracle: SQL and PL/SQL Using Procedure Builder 20Ć20 Introduction to Oracle: SQL and PL/SQL Using Procedure Builder ... blocks Therefore, use this lesson as a high level overview, with the details to follow in the next lessons Modularizing Programming with Subprograms 20Ć3 20Ć4 Introduction to Oracle: SQL and PL/SQL... Reference, Release 2.3, ? ?Subprograms. ” Class Management Note: Packages and other PL/SQL constructs are covered in the Develop Database Procedures course Modularizing Programming with Subprograms 20Ć5... Therefore, when creating the procedure from SQL*Plus, begin the statement with CREATE OR REPLACE Modularizing Programming with Subprograms 20Ć9 20Ć10 Introduction to Oracle: SQL and PL/SQL Using Procedure

Ngày đăng: 10/12/2013, 17:15

Từ khóa liên quan

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan