没有合适的资源?快使用搜索试试~ 我知道了~
首页Oracle PL/SQL编程指南:附带光盘内容详解
"Oracle PL SQL Programming" 是一本由O'Reilly出版的专业书籍,主要关注Oracle数据库中的过程化语言PL/SQL的编程技术。书中附带的伴侣磁盘包含了一些额外的资源和指南,帮助读者更好地理解和应用书中的概念。
本书详细讲解了PL/SQL的各种方面,包括如何安装和使用指南、调用存储过程的方法及其限制,以及Oracle提供的内置包的使用。在安装和使用指南部分,读者可以找到关于如何设置和利用这些资源以辅助学习的步骤。此外,书中的"Calling Stored Procedures from PL/SQL"章节深入探讨了从PL/SQL调用服务器端存储过程的方法,列出了使用存根与服务器通信的过程,以及在此过程中可能遇到的各种限制,如不支持服务器端PL/SQL数据类型、无法直接引用存储包变量、不能进行远程过程调用和默认参数值等。
在内置包部分,书中详细介绍了多个Oracle提供的重要包,例如DBMS_ALERT,它是一个用于异步通知的包,提供了注册、移除、清除默认设置、发送信号和等待通知等一系列方法。DBMS_AQ是Oracle的高级队列设施,包括DBMS_AQ和DBMS_AQADM两个子包,用于消息队列的管理和操作。DBMS_DDL包则提供了对数据库对象编译和分析的功能,如ALTER_COMPILE和ANALYZE_OBJECT等过程。DBMS_JOB包则是用来管理计划任务的,包含BROKEN、CHANGE和INTERVAL等过程,用于控制和调度数据库作业。
这些内容涵盖了PL/SQL编程的关键概念和技术,对于想要提升在Oracle数据库环境中编写高效、可靠代码的开发者来说,是一份非常有价值的参考资料。通过本书的学习,读者将能够熟练地运用PL/SQL来解决实际问题,创建复杂的业务逻辑,以及与Oracle数据库的各种组件进行交互。
Table of Contents
15.8.4 Restrictions on Overloading........................................................................................551
...........................................................................................................................................................................554
15.9 Forward Declarations...................................................................................................................554
...........................................................................................................................................................................556
15.10 Go Forth and Modularize!.........................................................................................................556
...........................................................................................................................................................................557
16. Packages.....................................................................................................................................................558
16.1 The Benefits of Packages.............................................................................................................559
16.1.1 Enforced Information Hiding.......................................................................................559
16.1.2 Object−Oriented Design..............................................................................................559
16.1.3 Top−Down Design.......................................................................................................559
16.1.4 Object Persistence........................................................................................................559
16.1.5 Performance Improvement..........................................................................................560
...........................................................................................................................................................................561
16.2 Overview of Package Structure...................................................................................................561
16.2.1 The Specification.........................................................................................................561
16.2.2 The Body......................................................................................................................562
16.2.3 Package Syntax............................................................................................................562
16.2.4 Public and Private Package Elements..........................................................................563
16.2.5 How to Reference Package Elements..........................................................................564
16.2.6 Quick Tour of a Package.............................................................................................565
...........................................................................................................................................................................569
16.3 The Package Specification...........................................................................................................569
16.3.1 Packages Without Bodies............................................................................................570
16.3.2 Declaring Package Cursors..........................................................................................573
...........................................................................................................................................................................575
16.4 The Package Body.......................................................................................................................575
16.4.1 Declare in Specification or Body.................................................................................575
16.4.2 Synchronize Body with Package.................................................................................576
...........................................................................................................................................................................578
16.5 Package Data................................................................................................................................578
16.5.1 Architecture of Package−Based Data..........................................................................578
16.5.2 Global Within a Single Oracle Session........................................................................579
16.5.3 Global Public Data.......................................................................................................579
16.5.4 Global Private Data......................................................................................................580
16.5.5 Providing an Interface to Global Data.........................................................................581
...........................................................................................................................................................................583
16.6 Package Initialization...................................................................................................................583
16.6.1 Drawbacks of Package Initialization...........................................................................583
16.6.2 Use Initialization Section for Complex Logic.............................................................583
16.6.3 Side Effects..................................................................................................................584
16.6.4 Load Session Data in Initialization Section.................................................................584
...........................................................................................................................................................................586
17. Calling PL/SQL Functions in SQL..........................................................................................................587
17.1 Looking at the Problem................................................................................................................587
...........................................................................................................................................................................590
17.2 Syntax for Calling Stored Functions in SQL...............................................................................590
...........................................................................................................................................................................592
[Appendix A] What's on the Companion Disk?
xv
Table of Contents
17.3 Requirements for Stored Functions in SQL.................................................................................592
...........................................................................................................................................................................594
17.4 Restrictions on PL/SQL Functions in SQL..................................................................................594
...........................................................................................................................................................................596
17.5 Calling Packaged Functions in SQL............................................................................................596
17.5.1 The RESTRICT_REFERENCES Pragma...................................................................596
17.5.2 Asserting Purity Level with Package Initialization Section........................................598
...........................................................................................................................................................................600
17.6 Column/Function Name Precedence............................................................................................600
...........................................................................................................................................................................601
17.7 Realities: Calling PL/SQL Functions in SQL..............................................................................601
17.7.1 Manual Application of Pragmas..................................................................................601
17.7.2 Read Consistency Model Complications.....................................................................602
...........................................................................................................................................................................604
17.8 Examples of Embedded PL/SQL.................................................................................................604
17.8.1 Encapsulating Calculations..........................................................................................604
17.8.2 Combining Scalar and Aggregate Values....................................................................605
17.8.3 Replacing Correlated Subqueries.................................................................................607
17.8.4 Replacing DECODEs with IF Statements...................................................................609
17.8.5 GROUP BY Partial Column Values............................................................................611
17.8.6 Sequential Processing Against a Column's Value.......................................................612
17.8.7 Recursive Processing in a SQL Statement...................................................................613
...........................................................................................................................................................................616
18. Object Types..............................................................................................................................................617
18.1 Introduction to Oracle8 Objects...................................................................................................618
18.1.1 Terminology.................................................................................................................618
18.1.2 Some Simple Examples...............................................................................................619
18.1.3 Comparison: Oracle8 Objects and Earlier Features.....................................................620
18.1.4 Characteristics of Objects............................................................................................621
18.1.5 Object Programming Themes......................................................................................623
...........................................................................................................................................................................627
18.2 Oracle Objects Example..............................................................................................................627
18.2.1 Defining the Object Type Specification......................................................................627
18.2.2 Defining the Object Type Body...................................................................................627
18.2.3 Adding Complex Data Structures................................................................................631
...........................................................................................................................................................................634
18.3 Syntax for Creating Object Types................................................................................................634
18.3.1 About Object Types.....................................................................................................634
18.3.2 CREATE TYPE and DROP TYPE: Creating and Dropping Types............................634
18.3.3 CREATE TYPE BODY: Creating a Body..................................................................636
18.3.4 Dot Notation................................................................................................................636
18.3.5 SELF: The Implied Parameter.....................................................................................639
18.3.6 Comparing Objects......................................................................................................640
18.3.7 Privileges.....................................................................................................................643
...........................................................................................................................................................................645
18.4 Manipulating Objects in PL/SQL and SQL.................................................................................645
18.4.1 The Need to Initialize..................................................................................................645
18.4.2 OID, VALUE, REF, and DEREF................................................................................647
...........................................................................................................................................................................655
[Appendix A] What's on the Companion Disk?
xvi
Table of Contents
18.5 Modifying Persistent Objects.......................................................................................................655
18.5.1 Approach 1: Permit Full Use of Conventional SQL....................................................656
18.5.2 Approach 2: Define Methods and Permit Limited Use of Conventional SQL............657
18.5.3 Approach 3: Do Everything via Methods....................................................................658
18.5.4 Approach 4: Use an Object and a PL/SQL Container Package...................................664
18.5.5 Implications for Developer/2000.................................................................................667
...........................................................................................................................................................................668
18.6 Object Housekeeping...................................................................................................................668
18.6.1 Data Dictionary............................................................................................................668
18.6.2 SQL*Plus "Describe" Command.................................................................................669
18.6.3 Schema Evolution........................................................................................................669
...........................................................................................................................................................................672
18.7 Making the Objects Option Work................................................................................................672
...........................................................................................................................................................................674
19. Nested Tables and VARRAYs.................................................................................................................675
19.1 Types of Collections....................................................................................................................675
...........................................................................................................................................................................680
19.2 Creating the New Collections......................................................................................................680
19.2.1 Collections "In the Database"......................................................................................680
19.2.2 Collections in PL/SQL.................................................................................................682
...........................................................................................................................................................................687
19.3 Syntax for Declaring Collection Datatypes.................................................................................687
...........................................................................................................................................................................689
19.4 Using Collections.........................................................................................................................689
19.4.1 Initializing Collection Variables..................................................................................689
19.4.2 Assigning Values to Elements: Index (Subscript) Considerations..............................693
19.4.3 Adding and Removing Elements.................................................................................693
19.4.4 Comparing Collections................................................................................................695
...........................................................................................................................................................................697
19.5 Collection Pseudo−Functions......................................................................................................697
19.5.1 The THE Pseudo−function..........................................................................................697
19.5.2 The CAST Pseudo−function........................................................................................699
19.5.3 The MULTISET Pseudo−function..............................................................................700
19.5.4 The TABLE Pseudo−function.....................................................................................702
...........................................................................................................................................................................704
19.6 Collection Built−Ins.....................................................................................................................704
19.6.1 COUNT........................................................................................................................705
19.6.2 DELETE [ ( i [ , j ] ) ]..................................................................................................705
19.6.3 EXISTS(i)....................................................................................................................706
19.6.4 EXTEND [ (n [,i] ) ]....................................................................................................706
19.6.5 FIRST, LAST...............................................................................................................707
19.6.6 LIMIT..........................................................................................................................707
19.6.7 PRIOR(i), NEXT(i).....................................................................................................708
19.6.8 TRIM [ (n ) ]................................................................................................................708
...........................................................................................................................................................................710
19.7 Example: PL/SQL−to−Server Integration...................................................................................710
...........................................................................................................................................................................713
19.8 Collections Housekeeping...........................................................................................................713
19.8.1 Privileges.....................................................................................................................713
19.8.2 Data Dictionary............................................................................................................713
19.8.3 Call by Reference or Call by Value.............................................................................714
...........................................................................................................................................................................715
[Appendix A] What's on the Companion Disk?
xvii
Table of Contents
19.9 Which Collection Type Should I Use?........................................................................................715
20.1 Example: Using Object Views.....................................................................................................716
...........................................................................................................................................................................717
20. Object Views..............................................................................................................................................718
...........................................................................................................................................................................723
20.2 INSTEAD OF Triggers................................................................................................................723
20.2.1 INSTEAD OF Triggers: To Use or Not to Use?.........................................................724
...........................................................................................................................................................................727
20.3 Syntax for Object Views..............................................................................................................727
20.3.1 CREATE VIEW: Creating an Object View................................................................727
20.3.2 DROP: Dropping Views and Triggers.........................................................................728
20.3.3 MAKE_REF: Returning a Virtual REF.......................................................................728
...........................................................................................................................................................................730
20.4 Differences Between Object Views and Object Tables...............................................................730
20.4.1 OID Uniqueness...........................................................................................................730
20.4.2 Using REFs with Object Views...................................................................................732
20.4.3 Storage of Virtual REFs...............................................................................................737
20.4.4 REFs to Nonunique OIDs............................................................................................737
...........................................................................................................................................................................738
20.5 Not All Views with Objects Are Object Views...........................................................................738
...........................................................................................................................................................................739
20.6 Schema Evolution........................................................................................................................739
...........................................................................................................................................................................741
20.7 Object Views Housekeeping........................................................................................................741
20.7.1 Data Dictionary............................................................................................................741
20.7.2 Privileges.....................................................................................................................742
20.7.3 Forcing Compilation....................................................................................................742
...........................................................................................................................................................................743
20.8 Postscript: Using the BFILE Datatype.........................................................................................743
...........................................................................................................................................................................746
21. External Procedures.................................................................................................................................747
21.1 Introduction to External Procedures............................................................................................748
21.1.1 Example: Determining Free Disk Space on Windows NT..........................................748
21.1.2 Architecture.................................................................................................................750
21.1.3 Advantages...................................................................................................................750
21.1.4 Limitations...................................................................................................................751
...........................................................................................................................................................................753
21.2 Steps in Creating an External Procedure.....................................................................................753
21.2.1 Step 1: Set Up the Listener..........................................................................................753
21.2.2 Step 2: Identify or Create the Shared Library..............................................................755
21.2.3 Step 3: Issue CREATE LIBRARY Statement.............................................................755
21.2.4 Step 4: Create the PL/SQL Body.................................................................................756
21.2.5 Using the rand External Procedure..............................................................................757
...........................................................................................................................................................................759
21.3 Syntax for External Procedures...................................................................................................759
21.3.1 CREATE LIBRARY: Creating the External Procedure Library.................................759
21.3.2 EXTERNAL: Creating the PL/SQL Body...................................................................760
21.3.3 DROP: Dropping Libraries..........................................................................................761
...........................................................................................................................................................................762
[Appendix A] What's on the Companion Disk?
xviii
Table of Contents
21.4 Mapping Parameters....................................................................................................................762
21.4.1 Datatype Conversion....................................................................................................762
21.4.2 More Syntax: The PARAMETERS Clause.................................................................764
21.4.3 Properties.....................................................................................................................765
21.4.4 Correct Declaration of Properties................................................................................767
...........................................................................................................................................................................769
21.5 OCI Service Routines..................................................................................................................769
...........................................................................................................................................................................770
21.6 External Procedure Housekeeping...............................................................................................770
21.6.1 Data Dictionary............................................................................................................770
21.6.2 Rules and Warnings About External Procedures.........................................................770
...........................................................................................................................................................................773
21.7 Examples......................................................................................................................................773
21.7.1 Example: Retrieving the Time Zone............................................................................773
21.7.2 Example: Sending Email.............................................................................................776
...........................................................................................................................................................................781
22. Code Design Tips.......................................................................................................................................782
22.1 Select Meaningful Module and Parameter Names.......................................................................782
22.1.1 Make Sure the Module Name Explains the Module....................................................782
22.1.2 Develop Consistent Naming Conventions for Your Formal Parameters.....................784
22.1.3 Name Packages and Their Elements to Reflect the Packaged Structure.....................785
...........................................................................................................................................................................787
22.2 Build the Most Functional Functions...........................................................................................787
22.2.1 Avoid Side Effects in Functions..................................................................................787
22.2.2 Use a Single RETURN Statement for Successful Termination...................................790
22.2.3 Avoid Exception Handlers for Normal Program Exits................................................793
22.2.4 Use Assertion Modules to Validate Parameters and Assumptions..............................794
...........................................................................................................................................................................798
22.3 Take Full Advantage of Local Modularization............................................................................798
...........................................................................................................................................................................801
22.4 Be Wary of Modules Without Any Parameters...........................................................................801
...........................................................................................................................................................................803
22.5 Create Independent Modules.......................................................................................................803
22.5.1 Stretch the Possibilities of the Module........................................................................804
22.5.2 Keep the Focus of Your Module..................................................................................804
22.5.3 Use Parameters Liberally.............................................................................................804
22.5.4 Avoid Global Variables and Data Structures...............................................................805
...........................................................................................................................................................................807
22.6 Construct Abstract Data Types (ADTs).......................................................................................807
22.6.1 Build an ADT in Phases...............................................................................................807
22.6.2 Some ADT Guidelines.................................................................................................808
22.6.3 Progress Box as ADT..................................................................................................808
22.6.4 Price Paid for Code Dispersion....................................................................................810
...........................................................................................................................................................................814
22.7 Tips for Parameter Design...........................................................................................................814
22.7.1 Document All Parameters and Their Functions...........................................................814
22.7.2 Use Self−Identifying Parameters (Avoid Boolean Values).........................................815
22.7.3 Assign Values to All OUT and IN OUT Parameters...................................................816
22.7.4 Ensure Case Consistency of Parameters......................................................................818
22.7.5 Default Values and Remote Procedure Calls...............................................................820
...........................................................................................................................................................................822
[Appendix A] What's on the Companion Disk?
xix
剩余983页未读,继续阅读
377 浏览量
109 浏览量
109 浏览量
149 浏览量
2011-02-23 上传
点击了解资源详情
点击了解资源详情
点击了解资源详情
点击了解资源详情
gerry320
- 粉丝: 0
- 资源: 9
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功