30
Chapter 13 CHAPTER 13 -------------------------------------------------------------------------------------------------------------------- - PROCEDURE S, FUNCTIONS, PACKAGES, AND TRIGGERS This chapter covers the creation of named database objects that store executable code. Oracl e subprogra ms include both proce dures and functi ons. These are named PL/!L bloc"s that can optiona ll# includ e one or more paramet ers. $hen calle d% a proced ure perfor ms a data  processing ac tion can return multiple values% &hile a function usuall# performs a calculation of some sort and returns a single value to the calling procedure. The chapter als o covers Oracle pac"ages. Li"e proce dures and funct ions% a pac"age  belongs to a schema. ' pac "age groups PL/!L t#pes% variables% exceptions% an d subprograms that are logicall# relat ed. Pac"ages ma"e it easier to develop applications b# providing a named PL/!L module &ith simple% &ell(defined interfaces. The chapter also teaches #ou to program database tr iggers. Triggers are PL/!L bloc"s that execute for predefined database events% such as the insertion of a ro& in a database table. Triggers are useful for activities such as the automation of data archiving and the enforcement of complex data integrit# rules. OBJECTIVES OBJECTIVES )n this chapter% #ou &ill learn the basic s"ills re*uired to+ Create and drop procedures , includes passing parameters and values. Create and drop functions , includes returning values. Create pac"age specifications% pac"age bodies% stored% pac"ages% cursor processing in  pac"ages% and calling stored pac"ages. Create% alter% drop% enable% and disable triggers , includes before and after triggers. PROCEDURES AND FUNCTIONS PROCEDURES AND FUNCTIONS -oth procedures and functions are class ifi ed as Ora cle  subprograms. -ot h pr oce dures and functions can be programmed to perf orm a data processing tas". unctions are t#picall# coded to  perform some t#pe of calculation. -oth procedures and functions are named PL/!L bloc"s% and both can be coded to ta"e parameters to generali e the code. -ot h can be &rit ten &it h declar ative% execut able% and exceptio n sections. The primar # differen ce is that proced ures are called &ith PL/!L statements &hile functions are called as part of an expression. )f this is not clear at this time% do not &orr# because the examples throughout this chapter &ill clarif# these t&o different t#pes of subprograms. )n previous chapters% #ou &or"ed &ith anon#mous PL/!L bloc"s. 0o& #ou &ill l earn to created named bloc"s that are stored as databa se object s. Procedu res and functions are normall# stored in the database &ithin pac"age specifications , a pac"age is a sort of &rapper for a group of named bloc"s. Proce dures and funct ions can also be store d as individual database object s. ' proced ure or fu nction i s parse d and comp iled at th e time it is sto red. 's a resu lt% evised+ 11(2(45 13 ( 1

Chapter13 Oracle

Embed Size (px)

Citation preview

8/12/2019 Chapter13 Oracle

http://slidepdf.com/reader/full/chapter13-oracle 1/30

8/12/2019 Chapter13 Oracle

http://slidepdf.com/reader/full/chapter13-oracle 2/30

8/12/2019 Chapter13 Oracle

http://slidepdf.com/reader/full/chapter13-oracle 3/30

8/12/2019 Chapter13 Oracle

http://slidepdf.com/reader/full/chapter13-oracle 4/30

8/12/2019 Chapter13 Oracle

http://slidepdf.com/reader/full/chapter13-oracle 5/30

8/12/2019 Chapter13 Oracle

http://slidepdf.com/reader/full/chapter13-oracle 6/30

8/12/2019 Chapter13 Oracle

http://slidepdf.com/reader/full/chapter13-oracle 7/30

8/12/2019 Chapter13 Oracle

http://slidepdf.com/reader/full/chapter13-oracle 8/30

8/12/2019 Chapter13 Oracle

http://slidepdf.com/reader/full/chapter13-oracle 9/30

8/12/2019 Chapter13 Oracle

http://slidepdf.com/reader/full/chapter13-oracle 10/30

8/12/2019 Chapter13 Oracle

http://slidepdf.com/reader/full/chapter13-oracle 11/30

8/12/2019 Chapter13 Oracle

http://slidepdf.com/reader/full/chapter13-oracle 12/30

8/12/2019 Chapter13 Oracle

http://slidepdf.com/reader/full/chapter13-oracle 13/30

8/12/2019 Chapter13 Oracle

http://slidepdf.com/reader/full/chapter13-oracle 14/30

8/12/2019 Chapter13 Oracle

http://slidepdf.com/reader/full/chapter13-oracle 15/30

8/12/2019 Chapter13 Oracle

http://slidepdf.com/reader/full/chapter13-oracle 16/30

8/12/2019 Chapter13 Oracle

http://slidepdf.com/reader/full/chapter13-oracle 17/30

8/12/2019 Chapter13 Oracle

http://slidepdf.com/reader/full/chapter13-oracle 18/30

8/12/2019 Chapter13 Oracle

http://slidepdf.com/reader/full/chapter13-oracle 19/30

8/12/2019 Chapter13 Oracle

http://slidepdf.com/reader/full/chapter13-oracle 20/30

8/12/2019 Chapter13 Oracle

http://slidepdf.com/reader/full/chapter13-oracle 21/30

8/12/2019 Chapter13 Oracle

http://slidepdf.com/reader/full/chapter13-oracle 22/30

8/12/2019 Chapter13 Oracle

http://slidepdf.com/reader/full/chapter13-oracle 23/30

8/12/2019 Chapter13 Oracle

http://slidepdf.com/reader/full/chapter13-oracle 24/30

8/12/2019 Chapter13 Oracle

http://slidepdf.com/reader/full/chapter13-oracle 25/30

8/12/2019 Chapter13 Oracle

http://slidepdf.com/reader/full/chapter13-oracle 26/30

8/12/2019 Chapter13 Oracle

http://slidepdf.com/reader/full/chapter13-oracle 27/30

8/12/2019 Chapter13 Oracle

http://slidepdf.com/reader/full/chapter13-oracle 28/30

8/12/2019 Chapter13 Oracle

http://slidepdf.com/reader/full/chapter13-oracle 29/30

8/12/2019 Chapter13 Oracle

http://slidepdf.com/reader/full/chapter13-oracle 30/30