0% found this document useful (0 votes)
19 views73 pages

Oracle9i PL SQL A Developer S Guide 1st Edition Bulusu Lakshman (Auth.) Download

Oracle9i PL/SQL: A Developer's Guide by Bulusu Lakshman is a comprehensive resource for learning PL/SQL, suitable for both beginners and experienced developers. The book covers a wide range of topics, from basic concepts to advanced techniques, with practical examples and detailed explanations. It emphasizes hands-on practice and includes insights on performance and coding standards, making it a valuable tool for Oracle professionals.

Uploaded by

suqinggrurl
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views73 pages

Oracle9i PL SQL A Developer S Guide 1st Edition Bulusu Lakshman (Auth.) Download

Oracle9i PL/SQL: A Developer's Guide by Bulusu Lakshman is a comprehensive resource for learning PL/SQL, suitable for both beginners and experienced developers. The book covers a wide range of topics, from basic concepts to advanced techniques, with practical examples and detailed explanations. It emphasizes hands-on practice and includes insights on performance and coding standards, making it a valuable tool for Oracle professionals.

Uploaded by

suqinggrurl
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 73

Oracle9i PL SQL A Developer s Guide 1st Edition

Bulusu Lakshman (Auth.) pdf download

https://ebookgate.com/product/oracle9i-pl-sql-a-developer-s-
guide-1st-edition-bulusu-lakshman-auth/

Get Instant Ebook Downloads – Browse at https://ebookgate.com


Instant digital products (PDF, ePub, MOBI) available
Download now and explore formats that suit you...

Advanced Oracle PL SQL Developer s Guide 2nd Edition


Saurabh K. Gupta

https://ebookgate.com/product/advanced-oracle-pl-sql-developer-s-
guide-2nd-edition-saurabh-k-gupta/

ebookgate.com

Oracle PL SQL Programming Animal Guide 5th Edition Steven


Feuerstein

https://ebookgate.com/product/oracle-pl-sql-programming-animal-
guide-5th-edition-steven-feuerstein/

ebookgate.com

Beginning PL SQL 1st Edition Donald Bales

https://ebookgate.com/product/beginning-pl-sql-1st-edition-donald-
bales/

ebookgate.com

Oracle PL SQL For Dummies 1st Edition Michael Rosenblum

https://ebookgate.com/product/oracle-pl-sql-for-dummies-1st-edition-
michael-rosenblum/

ebookgate.com
Learning Oracle PL SQL 1st ed Edition Bill Pribyl

https://ebookgate.com/product/learning-oracle-pl-sql-1st-ed-edition-
bill-pribyl/

ebookgate.com

Unlocking Android a developer s guide 1st Edition Frank


Ableson

https://ebookgate.com/product/unlocking-android-a-developer-s-
guide-1st-edition-frank-ableson/

ebookgate.com

PostgreSQL Developer s Guide 1st Edition Ahmed

https://ebookgate.com/product/postgresql-developer-s-guide-1st-
edition-ahmed/

ebookgate.com

Expert PL SQL Practices For Oracle Developers and Dbas 1st


Edition John Beresniewicz

https://ebookgate.com/product/expert-pl-sql-practices-for-oracle-
developers-and-dbas-1st-edition-john-beresniewicz/

ebookgate.com

Head First SQL Your Brain on SQL A Learner s Guide Head


First 1st Ed. Edition Lynn Beighley

https://ebookgate.com/product/head-first-sql-your-brain-on-sql-a-
learner-s-guide-head-first-1st-ed-edition-lynn-beighley/

ebookgate.com
Oracle9i PLISOL
- :
A Developer's Guide
BULUSU LAKSHMAN

Apress'"
Oracle9i PL/SQL: A Developer's Guide

Copyright © 2003 by Bulusu Lakshman


Originally published by Apress in 2003.

All rights reserved. No part ofthis work may be reproduced or transmitted in any form or byany
means, electronic or mechanical, induding photocopying, recording, or by any information
storage or retrieval system, without the prior written permission of the copyright owner and the
publisher.

ISBN 978-1-59059-049-2 ISBN 978-1-4302-1154-9 (eBook)


DOI 10.1007/978-1-4302-1154-9

Trademarked names may appear in this book. Rather than use a trademark symbol with every
occurrence of a trademarked name, we use the names only in an editorial fashion and to the
benefit of the trademark owner, with no intention of infringement of the trademark.

Technical Reviewer: Martin Reid


Editorial Directors: Dan Appleman, Gary Cornell, Jason Gilmore, Simon Hayes, Karen Watterson,
John Zukowski
Managing Editor: Grace Wong
Project Manager and Developmental Editor: Tracy Brown Collins
Copy Editors: Nicole LeClerc, Ami Knox
Production Editor: Laura Cheu
Compositor and Artist: Impressions Book and Journal Services, Inc.
Cover Designer: Kurt Krames
Indexer: Valerie Robbins
Marketing Manager: Stephanie Rodriguez
Manufacturing Manager: Tom Debolski

Distributed to the book trade in the United States by Springer-Verlag NewYork, Inc., 233 Spring
Street, 6th Floor, NewYork, NY 10013 and outside the United States by Springer-Verlag GmbH &
Co. KG, Tiergartenstr. 17,69112 Heidelberg, Germany.

In the United States, phone I-BOO-SPRINGER, email [email protected]. or visit


http://www.springer-ny.com.

Outside the United States, fax +496221345229, email [email protected], or visit


http://www.springer.de.

For information on translations, please contactApress directly at 2560 9th Street, Suite 2l9,
Berkeley, CA 94710. Phone 510-549-5930, fax 510-549-5939, email [email protected], or visit
http://www.apress.com.

The information in this book is distributed on an "as is" basis, without warranty. Although every
precaution has been taken in the preparation of this work, neither the author nor Apress shall
have any liability to any person or entity with respect to any loss or damage caused or alleged to
be caused directly or indirectly by the information contained in this work.

The source code for this book is available to readers at http://www.apress.comin the Source
Code/Downloads section.
With love to my parents, Professor B.S.KR. Somayajulu and Smt. B. Sita.
Contents at a Glance
Foreword ............................................................ .xiii

About the Author ................................................... .xv

About the Technical Reviewer .................................... .xvi

About the Foreword Writer ....................................... .xvii

Acknowledgments .................................................... .xix

Introduction ....................................................... .xxi

Part One: Introduction ............................................ 1

Chapter 1 Introduction to PL/SQL ................................ 3

Part Two: Non-Object-Oriented Features in PL/SQL 9i ........ 31

Chapter 2 Cursors ................................................ 33

Chapter 3 PL/SQL Records and Index-by Tables ................. 95

Chapter 4 Error Message Handling .............................. 137

Chapter 5 Stored Subprograms


(Procedures, Functions, and Packages) ............ 175

Chapter 6 Database Triggers ................................... .255

Chapter 7 Native Dynamic SQL and Dynamic PL/SQL ............ 291

Chapter 8 Autonomous Transactions ........................... .315

Chapter 9 Native Bulk Binds .................................... 333

Part Three: Object-Oriented Featuresin PLlSQL 9i ............ .359

Chapter 10 The World of Objects ................................ 361

Chapter 11 Collections (VARRAYS and Nested Tables) .......... 433

Chapter 12 Large Objects ....................................... .479

v
Part Four: PL/SQL with Java and the Web ...................... .507
Chapter 13 Floating in Java .................................... .509

Chapter 14 PL/SQL and the Web .................................. 555

Part Five: PL/SQL Performance and Standards .................. 595


Chapter 15 Performance Considerations ......................... 597

Chapter 16 PL/SQL Coding Standards ............................ 611

Part Six: Appendix .. ............................................ 629


Appendix A Case Studies and Schema Objects ................... 631

Index ................................................................. 637


Contents
Foreword ............................................................ .xiii
About the Author ................................................... .xv
About the Technical Reviewer .................................... .xvi
About the Foreword Writer ....................................... .xvii
Acknowledgments .................................................... .xix
Introduction ....................................................... .xxi

Part One: Introduction ........................................ 1

Chapter 1: Introduction to PL/SQL ........................ 3


Advantages of Using PL/SQL .......................................... 5
Building Blocks of PL/SQL ........................................... 7
Procedural Constructs in PL/SQL .................................. .10
PL/SQL Environments ................................................. 15
New Features of PL/SQL 9i ..........................................17
Summary .............................................................. .30

Part Two: Non-Object-Oriented Features


in PL/SQL 9i ..................................................... 31

Chapter 2: Cursors ............................................. 33


Introducing Cursors ................................................ 33
Cursor Variables .................................................... 65
Cursor Expressions ................................................. .80
Summary ............................................................... 94

vii
Contents

Chapter 3: PL/SQL Records and Index-by Tables ...... 95


Records ............................................................... 97
Index-by Tables .................................................... 114
Summary .............................................................. 135

Chapter 4: Error Message Handling ...................... 137


PL/SQL Exceptions : Types and Definition ........................ 137
Handling PL/SQL Exceptions ........................................ 143
User-Defined PL/SQL Error Messages .............................. 166
Tips for PL/SQL Error Message and Exception Handling ......... 172
Summary .............................................................. 173

Chapter 5: Stored Subprograms


(Procedures, Functions, and Packages) ................ 175
Creating and Using Procedures and Functions ................... 177
PL/SQL Packages ................................................... .201
Subprograms Returning Resultsets ................................ 217
Using Stored Functions in SQL Statements ...................... .220
Parameter Passing by Reference ................................. .231
Definer and Invoker Rights ....................................... 236
Additional Package Features ...................................... 242
Summary ............................................................. .253

Chapter 6: Database Triggers .............................. 255


PL/SQL Triggers: Types and Definition ......................... .256
Read-Only Views, Updateable Views,
and INSTEAD-OF Triggers ....................................... 275
New Database Triggers ............................................. .282
Summary ............................................................. .290

viii
Contents

Chapter 7: Native Dynamic SQL


and Dynamic PL/SQL ........................................... 291
DBMS_SQL vs. Native Dynamic SQL ................................ .292
Native Dynamic SQL Statements .................................... 295
Dynamic DDL ......................................................... 296
Dynamic SE LECTS ................................................... .300
Dynamic INSERT, UPDATE, and DE LETE ............................. .307
Using Bind Variables ............................................. .308
Dynamic PL/SQL .................................................... .310
Exception Handling in Native Dynamic SQL ...................... .312
Native Dynamic SQL and Objects .................................. 313
Summary .............................................................. 313

Chapter 8: Autonomous Transactions ................... .315


Transaction Management Prior to
Autonomous Transactions ....................................... 315
Autonomous Transactions : Definition and Use .................. .316
Summary .............................................................. 331

Chapter 9: Native Bulk Binds ............................. 333


Bulk DML ............................................................. 334
Bulk Query .......................................................... 346
Bulk Dynamic SQL ................................................... 354
Summary .............................................................. 357

Part Three: Object-Oriented Features


in PL/SQL 9i .................................................... 359

Chapter 10: The World of Objects ...................... .361


Object Types and Object Tables .................................. 362
Type Inheritance ................................................... 399
Dynamic Method Dispatch .......................................... .409
Type Evolution .................................................... .411

ix
Contents

Java Object Storage: SQL Types of Language Java


or SQLJ Object Types ......................................... .417
User-Defined Operators ........................................... .423
Summary ............................................................. .431

Chapter 11: Collections


(VARRAYS and Nested Tables) ............................. .433
Creating and Using Collections in PL/SQL ...................... .433
Table Functions ................................................... .464
Multilevel Collections ........................................... .473
Summary ............................................................. .478

Chapter 12: Large Objects ................................ .479


LOBs Overview ...................................................... .479
BLOBs ............................................................... .480
CLOBs ............................................................... .482
BFILEs .............................................................. .485
DBMS _ LOB Package .................................................. .487
TO LOB Function ................................................... .502
Summary ............................................................. .505

Part Four: PLISQL with Java and the Web ............ .507

Chapter 13: Floating in Java ............................ .509


Using Java in the Database ...................................... .509
PL/SQL Calling Java: Java Stored Procedures ................... 511
Creating Java Stored Procedures ................................. 513
Executing Java Stored Procedures ................................ 544
Java Stored Procedures Returning Resul tsets .................... 549
Summary .............................................................. 554

x
Contents

Chapter 14: PL/SQL and the Web ........................... 555


Using HTML in PL/SQL ............................................... 556
PL/SQL in HTML: PL/SQL Server Pages ............................ 573
Building an Application for the Web Using PL/SQL ............. 579
Sending E-mail Using PL/SQL ....................................... 589
Summary .............................................................. 593

Part Five: PL/SQL Performance and Standards ....... 595

Chapter 15: Performance Considerations .............. 597


Some PL/SQL Tuning Procedures .................................... 598
Native Compilation of PL/SQL Code ............................... 599
Parameter Passing by Reference ................................. .602
Using Native Dynamic SQL ........................................ .604
Using Bulk Binds .................................................. .605
Using the RETURNING Clause ...................................... .607
Using Object Types and Collections ............................. .608
Using Pipelined Table Functions ................................ .608
Summary ............................................................. .609

Chapter 16: PL/SQL Coding Standards ................... 611


Coding Standards ................................................... 612
Summary .............................................................. 627

Part Six: Appendix ........................................... 629

Appendix A: Case Studies and Schema Objects ....... 631


Organizational Hierarchy System ................................. 632
Order Entry Application System .................................. 635

Index ............................................................... .637

xi
Foreword
I HAD ALREADY READ a couple of chapters of Bulusu Lakshman's book on Orade9 i
PLlSQL when I was asked to write this Foreword. I immediately accepted
because of the strong impression the book made on me.
There have been several PLlSQL titles published over the years, but I think
Bulusu's book is the best Orade PLlSQL book ever written. There are several rea-
sons for this emphatic dedaration, one of them being that Oracle9i PLlSQL:
A Developer's Guide is the most comprehensive book on the subject, period. It
takes readers from the basics to the most complex techniques. Moreover, what's
most important is that Bulusu doesn't just "cover" the topics-he leads readers
step by step through the various techniques. The examples in this book use an
actual Orade9 i database and some sampie schemas, and the data is all right
there for you to leam or verify the techniques. Like mathematics, PLlSQL is an
endeavor in which you need to practice the examples to get good at the game.
You don't have to know any PLlSQL to start using this book, and ifyou persevere
and try the multitude of tested examples Bulusu provides, you might very weIl
become an expert in PLlSQL in short order.
Bulusu has set hirns elf a lofty goal: to write a comprehensive book on PLlSQL
that is technically complete and accessible to even the beginn er. I am glad to
confirm that Bulusu has succeeded in achieving his goal. Orade professionals at
various career stages, from fledgling newbies to seasoned veterans, will find this
book a treasure trove of useful examples and lucidly explained concepts.
The very first chapter, which intro duces PLlSQL, sets the tone for the book,
and Bulusu carefully and painstakingly builds on this chapter. The next chapter
(Chapter 2) covers cursors, and it provides the best treatment of the subject
that I've seen in any book. The chapter on record types and index-by tables
(Chapter 3) is also exceIlent. Bulusu takes care throughout the book to provide
useful information to his readers. Two examples of this are the tips for PLlSQL
error messages in Chapter 4 and the performance-improving tips in Chapter 15.
The chapter on triggers (Chapter 6) is another good example of how this book
stands out from many of the other titles on the market: You not only leam about
aIl there is to leam ab out creating and deploying triggers, but you also leam
about the dba_tables that contain pertinent information for managing triggers,
details about enabling and disabling triggers, and the privileges you need to be
able to use triggers. Typically, authors explain a concept, provide some examples,
and move on, but Bulusu consistently endeavors to provide a complete treat-
me nt of each topic so readers can not only leam what the concept means, but
also implement the concept successfully in the real world.

xiii
Foreward

Orade provides its own manuals, but they do not always offer a fruitful way
for developers to learn new and complex techniques. Bulusu takes you beyond
what any Orade manual can show you ab out using the innovations in Orade9 i
PLlSQL. Chapter 7, which covers native dynamic SQL, is a good example of this.
The chapter is a very useful yet simple and systematic tutorial-like introduction
to complex topics such as dynamic bulk SQL and dynamic PLlSQL. Bulusu cov-
ers a lot of ground in this book and indudes solid treatments of topics such as
Java stored procedures (Chapter 13) and PLlSQL and the Web (Chapter 14). The
latter chapter shows you how to Web-enable your PLlSQL code. Chapter 15 alone
makes the book an indispensable volume for any professional who uses or
intends to use PLlSQL-in it, Bulusu provides the most comprehensive set of
PLlSQL performance-enhancing hints and guidelines that you can find any-
where. And Bulusu's chapter on PLlSQL co ding standards (Chapter 16) contains
the most comprehensive co ding guidelines that you can find. In fact, most
PLlSQL books give short shrift to this very important part of PLlSQL implemen-
tation. It is chapters like these that make Bulusu's book astandout among the
current crop of Orade books.
Bulusu's book is an important addition to the Orade9 i literature, and it will
remain a favorite book on many a developer's desk in the years to come. Enjoyyour
voyage through the new Orade9iPLlSQL world, with Bulusu's book byyour side!

Sam Alapati
October 4,2002

xiv
About the Author
Bulusu Lakshman is an experienced Orade developer with
more than 10 years of extensive software design and develop-
ment experience in using Orade and its related tools, induding
PL/SQL and Java. He's the author of Orade Developer Forms
Techniques and Orade and Java Development, both of which
have been weil received. He also has an Orade Master creden-
tial from Orade Corporation, is an Orade Certified Professional (OCP) application
developer, and is a double honors graduate in computer science and engineering
and mathematics. He has presented at numerous international and national
conferences on Orade and its tools and published artides in various technical
magazines and journals in the United States and the United Kingdom. He is cur-
rently employed by Compunnel Software Group Inc., a leading technical
consulting firm based in New Jersey.

xv
About the Technical
Reviewer
Martin W.P. Reid is currently employed at Queen's University
Belfast, where he is responsible for staff and student com-
puter training, teaching everything from Windows to Web
authoring to database design. He is also employed by the
faculty of computer science as apart-time lecturer in database
design and teaches several courses using Microsoft Access
for other areas of the university.
Martin particularly enjoys the contact with staff and students, and one of his
biggest thrills was when two of his part-time students-who had previously never
been near a database-started to work as developers.
Martin is married with six children. He credits his wife, Patricia, with keeping
the whole show on the road while he plays with databases.

xvi
About the Foreword
Writer
Sam R. Alapati is an experienced Orade database administrator who holds the
Orade OCP DBA and the Hewlett Packard UNIX System Administrator certifi-
cations. He currently manages Orade databases at the Boy Scouts of America's
National Office in Los Colinas, Texas. Sam has been dealing with databases for
a long time, induding the Ingres RDBMS in the mid-1980s. In addition, he is weIl
versed in the Sybase and IBM DB2 database management systems. Sam has also
taught Orade DBA dasses for system administrators.

xvii
Acknowledgments
I THANK MYWIFE, Anuradha, for her eonsistent endeavor in ereating a positive
atmosphere throughout the writing period of my book.
I thank my brother B. Rama for his eonstant eneouragement throughout.
I thank Mr. Paul Wu, direetor of MIS at Assoeiated Press, the dient eompany
for whieh I am eonsulting, for providing me with neeessary resourees to write
this book.
I thank my friends V. Satya Prasad and Devendra Trivedi for their help in
preparing part of the manuseript and providing valuable suggestions.
I thank Mr. Vinayak Rampalli and Mr. Rakesh Shah of Compunnel Software
Group Ine. for letting me use the name of themail server as an example for one of
the programs in my book.
I thank Apress' publisher, Gary Cornell, and the various editors at Apress for
their help in editing and publishing my book.

xix
Introduction

Introduction
ORACLE9IIS THE major relational database management system (RDBMS) for

developing and running a wide variety of applications, starting from creating


and maintaining simple databases in client/server environments to conducting
e-business on the Web. PLlSQL is the primary procedural component of
Oracle9 i's server-side programming and is regarded as the primary language for
developing applications on the database and middle tiers using Oracle9i. PLlSQL
in Releases 1 and 2 of Oracle9 i has incorporated new features that take pro gram -
mers to a higher level of coding, especially with its true object-relational
capabilities. Also, Oracle9 i provides for support of Java in the database, and
PLlSQL 9 i provides this capability by me ans of Java stored procedures and their
new functionality in 9 i, to build highly scalable applications.

Wh at This Book Covers


This book covers the techniques ofusing PLlSQL in Oracle9iReieases 1 and 2 for
server-side applications. It covers PLI SQL 9 i in exhaustive detail and provides the
methodology for implementing robust applications of exceptional quality. This
book will assist programmers in implementing techniques that are effective for
real-world and code-centric Oracle applications. This saves time and effort on
the part of the PLlSQL developer in addition to increasing his or her level to that
of an advanced developer. Also, PLlSQL is widely used by many organizations,
and the combination of Oracle9i and PLlSQL provides a robust and effective
environment for development of mission-critical applications. This book is
a source for development of such applications by companies incorporating these
technologies as weIl as those organizations migrating from earlier versions.

How This Book Is Organized


This book is divided into 6 parts containing 16 chapters and 1 appendix, as follows.

Part One: Introduction


This part, which consists of Chapter 1, introduces you to the fundamental
constructs ofthe PLlSQL language and the development and execution
environments for PLlSQL pro grams.

xxi
Introduction

Part Two: Non-Object-Oriented Features


in PL/SQL 9i
This part presents the non-object-oriented features in PLlSQL 9i and is com-
posed of eight chapters. It covers details about cursors in Chapter 2, index-by
tables and PLlSQL re cords in Chapter 3, error message handling in Chapter 4,
stored subprograms (specifically, procedures, functions, and packages) in
Chapter 5, database triggers in Chapter 6, native dynamic SQL and dynamic
PLlSQL in Chapter 7, autonomous transactions in Chapter 8, and native bulk
binds in Chapter 9.

Part Three: Object-Oriented Features In PL/SQL 9i


This part explains the ins and outs ofusing objects in PLlSQL and is composed
of three chapters. Chapter 10 explains the use of different types of objects.
Chapter 11 explains collections and their use in PLlSQL in detail. Chapter 12
highlights the use oflarge objects in PLlSQL.

Part Four: PL/SQL with Java and the Web


This part, which consists of two chapters, deals with using PLlSQL in con-
junction with Java and using PLlSQL applications on the Web. Specifically,
Chapter 13 covers using PLlSQL with Java by means ofJava stored procedures,
and Chapter 14 covers Web-enabling PLlSQL applications.

Part Five: PL/SQL Performance and Standards


This part outlines some methods ofimproving the performance ofPLlSQL
applications and certain standards to followwhen co ding using PLlSQL. It is
composed of two chapters. Chapter 15 presents performance considerations,
and Chapter 16 presents some co ding standards to keep in mind when writing
PLlSQL programs.

Part Six: Appendix


This part, which consists of Appendix A, provides the case studies and some of
the schema objects necessary to run pro grams provided in this book.

xxii
Introduction

Prerequisites and Intended Audience


This book is targeted toward intermediate-level Grade developers who are
designing or co ding applications in SQL and PLlSQL. It assumes a working
knowledge of Grade SQL, PLlSQL, and Java. This book is also a guide for pro-
grammers who intend to use advanced PLlSQL 9 i features. It discusses Grade9 i
PLlSQL from an application developer's perspective.

xxiii
Part One
Introduction
CHAPTER 1

Introduction to PLISOL
-
ORACLE FIRST INTRODUCED Pro ce dural Language/Structured Query Language
(PLlSQL) in version 6.0 ofits relational database management system (RDBMS).
As its RDBMS evolved, Orade made developmental changes to the PLlSQL lan-
guage by introducing new features and enhancing existing features. As of
Orade9i, the version of PLlSQL is PLlSQL 9.2 or 9.0 depending on whether it
is Orade9 i Release 2 (9.2.x) or Orade9 i Release 1 (9.0.x). In this book, I refer to
both versions collectively as PLlSQL 9i.
PLlSQL incorporates third-generation language (3GL) structures otherwise
unavailable in Structured Query Language (SQL). SQL is a fourth-generation lan-
guage (4GL) , meaning it uses constructs and elements that specify "wh at to do"
without having to specify "how to do it." It's a major language for the Orade
RDBMS (as weIl as for other RDBMSs), and it's used for data definition, database
querying, and data manipulation and control. However, there are situations that
demand the use of 3GL constructs, such as conditional or iterative execution of
SQL and the like. This kind of logic and control flow can be achieved only in
a 3GL language such as Java, C++, or C. To accommodate 3GL features, Orade
designed and implemented the PLlSQL language as a procedural extension to
SQL. PLlSQL is integrated with SQL, and both SQL and PLlSQL serve as the
major database server-side languages, with each language complementing the
other. You can also use PLlSQL in dient-side environments.
Table 1-1 offers a comparison ofPLlSQL with other 3GLs such as Java,
C++, andC.

3
Chapter 1

Table 1-1. Comparison of PLlSQL with Other 3GLs


FEATURE Pl/SQl OTHER 3GlS (JAVA, C++, C)
Ease ofuse Fairlyeasy Difficult; requires a steep learning
curve

Portability of Highly portable Portable except for system caHs


applications

Integration Tightly integrated Integrated to a lesser degree than


with SQL PLlSQL; access by means of SQLJ
or IDBC
SQL-intensive WeH suited Not weH suited
operations

Compute-intensive Not weH suited WeH suited (e.g., for sorting of


operations large arrays)

Object orientation Object oriented to a Truly object oriented (like Java


certain extent and C++)

In this chapter, I describe the building blocks of PLlSQL and discuss the
various PLlSQL environments. I also highlight the new features of PLlSQL 9i.

ABrief History of PL/SQL


PLlSQL was first introduced in 1991 with Orade 6.0. It was provided as the "pro-
cedural option" on the server side. At the same time, it was subsequently
introduced on the dient side with SQL*Forms version 3.0 having a PLlSQL
engine of its own. The first version of PLlSQL, PLlSQL l.0, had very limited pro-
cedural features. But one of its strong points was its capability to process
multiple SQL statements mixed with procedural constructs.

PLlSQL has its roots in ADA, a high-level programming language. The concept
of the PLlSQL block resembles the concept ofblock structure in ADA using
BEGIN and END blocks. PLlSQL shares other features with ADA such as the
syntax "=" used for comparison and ":=" used for assignment, exception han-
dling, and the dedarative syntax of defining stored subprograms.

Over the years, Orade came up with new releases of PLlSQL. With Orade 7.0,
Orade released PLlSQL 2.0, which turned Orade into an active database with
the capability to store business and application logic in the database in the
form of stored procedures, functions, and packages. It also defined the capabil-
ity to dedare programmer-defined re cords and arrays in the form of PLlSQL
tables. PLlSQL 2.1 came into existence with Orade 7.1 and enabled the use of
stored functions in SQL statements. Also, dynamic SQL was introduced in

4
Introduction to PLlSQL

PLlSQL for the first time with the DBMS_SQL package. Orade 7.2 was released
subsequently, and along with it came PLlSQL 2.2. It had the capability to define
binarywrappers for PLlSQL stored subprograms, thus hiding code from other
developers. Also, the DBMS~OB package was introduced, which enabled pro-
grammers to sub mit jobs from within the database. The next release of PLlSQL
was PLlSQL 2.3, which was introduced with Orade 7.3. It enhanced the capabil-
ities of PLlSQL tables with the ability to define new methods, and it also
enabled programmers to access the file system from within the database. File
I/ 0 could be done using the UTL_FILE package.

Orade 8.xwas a major breakthrough in the Orade database history with the
introduction of objects and Java in the database. PLlSQL 8.xwas released along
with Orade 8.x and induded major features such as native dynamic SQL, Java
stored procedures, and system- and schema-level database triggers.

Finally, Orade9i was released and along with it came PLlSQL 9.2 and 9.0, corre-
sponding to Releases 2 and 1 of Orade9 i. This release saw the introduction of
native compilation ofPLlSQL code, enhancement to PLlSQL cursors in the
form of cursor express ions, new data types, enhancements to bulk binding,
pipelined table functions, true inheritance among objects, and more.

Advantages of Using PL/SQL


PLlSQL is a block-structured language that enables you to encapsulate business
logic in one place. This is by far the greatest advantage of PLI SQL that I've lever-
aged. Also, PLlSQL code runs on the server side, thus providing direct interaction
with the database and the SQL engine. Other advantages ofusing PLlSQL are
outlined in the following sections.

Procedural Capabilities
The primary advantage ofPLlSQL is its capability to define and implement 3GL
constructs with embedded SQL statements. Using PLlSQL, you can implement
standard 3GL capabilities, such as support for BOOLEAN data types; sequential,
conditional, and iterative logic; arrays and subprograms; and object-oriented
features. And you can do this side by side with SQL. This support for SQL in
PLlSQL makes PLlSQL powerful. The capability to define 3GL constructs is pri-
marily beneficial when you use PLlSQL in writing applications that mix and
match business logic that's complicated and necessary. Also, PLlSQL is the pri-
mary procedurallanguage for Orade dient-side tools such as Orade Forms and
Orade Reports.

5
Chapter 1

Portability
Pro grams written in PLlSQL are hardware independent and operating system
independent. They are highly portable and work well on any platform where an
Orade server and an integrated development environment (IDE) are installed.

Tight Integration with SQL


Orade has integrated SQL and PLlSQL. Programs written in PLlSQL can make
use of almost all SQL features such as SQL data types and the NULL construct.
Also, as ofOrade9i, there's an integrated SQL and PLlSQL parser. This means the
same parser is used for SQL and PLlSQL code, which results in more efficient
performance.

Modularity
PLlSQL enables you to write programs as independent modules that you can
integrate. You can implement this modularity by using features such as proce-
dures, functions, and packages.

Better Performance
PLlSQL offers better performance for three main reasons:

1. Data type conversion isn't needed on input and output. When data is
retrieved into PLlSQL variables or when data is input into Orade using
PLlSQL variables, PLlSQL takes care ofthe appropriate conversion
between the Orade server and PLlSQL by me ans of the same internal
database format. Other 3GL programs written in C++ or Java to access an
Orade database are required to convert data to and from Orade format
to C++/Java format.

2. Generally, database applications run in a dient -server environment are


deployed in either a two-tier architecture (Orade RDBMS on the server
and the PLlSQL application on the dient) or a three-tier structure (a
database server layer, an application server layer on an application
server, and a presentation layer on a dient). With PLlSQL, you can group
a set of SQL statements (along with application logic) into a PLlSQL
block and you can submit the entire block over to the Orade server. This
reduces network traffic in a two-tier or three-tier application structure

6
Introduction to PLlSQL

and thus improves performance. This concept ofblock structuring also


means fewer database calls, which results in better performance.

3. PLlSQL 9iintroduces native compilation ofPLlSQL code, and subse-


quent conversion to C and storage in machine code. This results in faster
execution. Prior to Oracle9i, the interpreted versions ofPLlSQL code,
known as p-code, exhibited only fairly fast execution of PLlSQL.

Object Orientation
PLlSQL provides object-oriented features such as encapsulation, abstraction (the
ability to define abstract data types), data and information hiding, reusability,
inheritance, polymorphism, and dynamic method dispatch. Various features
introduced in PLlSQL, from its earlier versions to PLlSQL 9i, enable object orien-
tation to be defined and implemented in PLlSQL. I discuss these features
throughout this book.

Building Blocks of PL/SQL


The basic co ding element ofpLlSQL is the block. A PLlSQL block imitates the
concept of block structuring inherent in structured programming languages such
as Pascal. Each block is a discrete set of code that would normally perform a cer-
tain function. A PLlSQL block also provides modularization of code into logically
related units of code. A typical PLlSQL block begins with a BEGIN statement and
ends with an END statement followed by a semicolon (;). There are three types of
PLlSQL blocks:

1. Anonymous block: This is a section of code enclosed within BEGIN and


END statements. It has no name associated with it.

2. Labeled block: This is a PLlSQL block identified by a label. It starts with


a PLlSQL label followed by a BEGIN and an END statement.

3. Named block: This is a PLlSQL block stored in the database as a subpro-


gram and identified by a unique name. This block is implemented by
means of stored subprograms and database triggers.

Whatever the type, a PLlSQL block consists of the following sections defined
within it:

7
Chapter 1

• Declaration section: This section begins with the DECLARE keyword and
contains declarations of variables, constants, cursors, and local subpro-
grams. This section is optional for a block.

• Executable section: This section begins with a BEGIN statement and con-
sists of procedurallogic and SQL statements. It ends with an END
statement.

• Exception handling section: This section begins with the EXCEPTION


WHEN keywords and contains logic for handling PL/SQL and/ or Oracle
server errors. Although this section is optional, it's a recommended pro-
gramming practice to always include an exception handling section.

A PL/SQL Block Example


Here's an example of a PL/SQL block. You should create the following table before
you execute this PL/SQL block.

CREATE TABLE items tab (item_code varchar2(6) PRIMARY KEY,


item_descr varchar2(20) NOT NULL);

Listing 1-1 shows the sampie PL/SQL block.

Listing 1-1. A Sample PLlSQL Block

DECLARE
v_item_code VARCHAR2(6);
v_item_descr VARCHAR2(20);
BEGIN
v_item_code := 'ITM10l';
v_item_descr := 'Spare parts';
INSERT INTO items_tab VALUES (v_item_code, v_item_descr);
EXCEPTION WHEN OTHERS THEN
dbms_output.put_line(SQLERRM);
END;
/

The program in Listing 1-1 declares two PL/SQL variables named v_item_code
and v_item_descr to store the item code and description, respectively. It initializes
these two variables with specific values and then inserts into the items_tab table
with values held in these two variables. Any errors that occur in the process are

8
Introduction to PLlSQL

output to the screen buffer with a corresponding error message. This is done
by a call to a special procedure named dbms_output.puUine, a packaged proce-
dure that outputs to the SQL*Plus screen with a corresponding message passed as
input to it. To make this procedure work, the SQL*Plus environment variable
SERVEROUTPUT should be set to ON. Here's the code to do this in SQL*Plus:

SQL> set serveroutput on;

A Nested Block Example


You can nest PLlSQL blocks, and the level of nesting is arbitrary. Listing 1-2 is an
example of the PLI SQL code in Listing 1-1 modified to include a nested block.

Listing 1-2. The Modijied PLlSQL Code That Uses a Nested Block

DECLARE
v_item_code VARCHAR2(6);
v_item_descr VARCHAR2(20);
v_num NUMBER(l);
BEGIN
v_item_code := 'ITM10l';
v item descr := 'Spare parts';
BEGIN
SE LECT 1
INTO v num
FROM i tems tab
WHERE item code = v_item_code;
EXCEPTION
WHEN NO DATA FOUND THEN
v_num := 0;
WHEN OTHERS THEN
dbms_output.put_line('Error in SELECT: 'IISQLERRM);
RETURN;
END;
IF (v_num = 0) THEN
INSERT INTO items tab VALUES (v_item_code, v_item_descr);
END IF;
dbms_output.put_line('Successful Completion' ) ;
EXCEPTION WHEN OTHERS THEN
dbms_output.put_line(SQLERRM);
END;
/

9
Chapter 1

Note the following with regard to this example PLlSQL block:

• There's an inner PLlSQL block nested in the outer PLlSQL block. This
inner block begins with the second BEGIN statement.

• Each PLlSQL block starts with a BEGIN statement and ends with an END
statement.

• SQL statements are embedded within 3GL constructs.

• Any PLlSQL block can have an optional dedaration section. In the preced-
ing example, the outer block has a dedaration section but the inner block
doesn't.

• Each PLlSQL block has its own exception handling section. !t's up to the
program to handle exceptions in each block. Any uncaught exceptions in
the nested block propagate to the exception handler in the immediate
outer block. If an exception isn't caught at all in any of the blocks, it results
in an unhandled exception, and control transfers out ofthe pro gram.

HP Always define an exception handling section in each


PL/SQL block-even in the case ofnested blocks.

The next section highlights the various procedural constructs available in


PLlSQL.

Procedural Constructs in PL/SQL


The 3GL features available in PLlSQL are as follows:

• Support of the BOOLEAN data type, reference cursor (REF CURSOR) types,
and user-defined subtypes (not available in the Orade server)

• New data types introduced in Orade9i such as TIMESTAMP and


INTERVAL, as well as user-defined types and conditional constructs
such as IF THEN ELSE

• CASE statements and expressions (as ofOrade9z)

10
Introduction to PLlSQL

• Iterative constructs such as loops (LOOP ... END LOOB FOR LOOB and
WHILE LOOP), single-dimensional arrays, and re cords

• Collection types (nested tables and varrays)

• Subprograms such as procedures, functions, and packages

• Object-oriented features

This section covers conditional constructs, CASE statements and


expressions, and iterative constructs. I discuss arrays, re cords, and collections,
subprograms, and object-oriented features in later chapters.

Conditional Constructs
A conditional construct executes a set of statements based on a condition being
true. It's specified by the IF statement. Here's the syntax:

IF (conditionl) THEN
[actionl]
ELSIF (condition2) THEN
[action2]
ELSIF (condition3) THEN
[action3]

ELSE
[actionN]
END IF;

In the preceding code, conditionl, condition2, and condition3 evaluate to


BOOLEAN TRUE or FALSE. If a condition evaluates to TRUE, the action und er it is
performed. If one condition evaluates to TRUE, the other conditions in the IF
chain arent checked.
The order in which the IF or ELSIF branches are written is important, as this
determines which one of the actions is to be executed.
Here's an example of the IF statement:

DECLARE
a number 50;
b number -20;
BEGIN
IF (a>b) THEN
dbms_output.put_line('A is greater than B');

11
Chapter 1

ELSIF (a<b) THEN


dbms_output.put_line('A is less than B');
ELSE
dbms_output.put_line('A is equal to B');
END IF;

You can nest the IF statement. However, good pragramming practice recom-
mends that you avoid nested IFs wherever possible and use ELSIF instead.

HP Using ELSIF instead ofnested IFs wherever possible


eliminates the conjusion of an IF . .. ELSE mismatch, and
it's less error-prone. It also improves performance because
onlya specijic leg of the IF statement is executed in the case
ofELSIF as opposed to nested IFs.

CASE Statements and Expressions


The CASE statementis a conditional construct first intraduced in PLlSQL 9i. It is
an alternative to the IF statement, but it's more elegant. There are two types of
CASE statements: the normal CASE statement and the searched CASE statement.
Similarly, CASE expressions are analogues of CASE statements when used in an
expression. I discuss them in the section "New Features ofPLlSQL 9i" later in this
chapter.

Iterative Constructs
Iterative constructs are specified by means of loops. There are three types of
loops that perform repetitive contral flow, namely the simple LOOp, the numeric
FOR LOOp, and the WHILE LOOP. Each of these loops ends with an END LOOP
statement.

The Simple LOOP

Here's the syntax of the simple LOOP:

LOOP
[statementl]
[statement2]

12
Introduction to PLlSQL

EXIl WHEN (condition);


END LOOP;

In the preceding code, statementl, statement2, and so forth refer to the exe-
cutable statements constituting the body of the loop, and condition refers to the
EXIT condition for the loop when the contral exits the loop. If the EXIT condition
isn't specified, the execution would result in an infinite loop. Here's an example of
the simple LOOP:

DECLARE
line_length NUMBER:= 50;
separator VARCHAR2(1) := '=';
actual_line VARCHAR2(150);
i NUMBER 1;
BEGIN
LOOP
actual line := actual line I I separator;
EXIl WHEN i = line_length;
i: = i + 1;
END LOOP;
DBMS_OUlPUl.PUl_LINE(actual_line);
END;
/

This pragram displays a line made of equal signs (=) whose length equals 50.
The index of the loop has to be explicitly defined, initialized, and incre-
mented. The body of the loop must have an explicit EXIT condition specified.

The FOR LOOP

You can write the same simple LOOP as a numeric FOR LOOP or a WHILE LOOP.
The FOR LOOP has the following syntax:

FOR index IN initialval .. finalval LOOP


[statementl]
[statement2]

END LOOP;

In the preceding code, index refers to a variable that increments the count
for the duration of the loop, and initialval and finalval refer to the initial and final
values that the index will take when looping. The difference between these two

13
Chapter 1

values plus 1 gives the number oftimes the contral repetitively executes the
statements in the body of the loop-that is, between FOR LOOP and END LOOP.
Here's the line display example written using a numeric FOR LOOP:

DECLARE
line_length NUMBER:= 50;
separator VARCHAR2(1) := '=';
actual_line VARCHAR2(150);
BEGIN
FOR idx in 1.. 1ine_length LOOP
actual_line : = actual_line 11 separator;
END LOOP;
DBMS_OUTPUT.PUT_LINE(actual_line);
END;
/

You dont need to declare the index of the FOR LOOP. Also, you don't need to
initialize the index, and you need not increment the index for each iteration of
the loop. You don't need an EXIT condition for the loop.

The WHILE LOOP

Next, I discuss the WHILE LOOP. Here's the syntax:

WHILE (condition) LOOP


[statement1]
[statement2]

END LOOP;

Here's the same line display example using a WHILE LOOP:

DECLARE
line_length NUMBER:= 50;
separator VARCHAR2(1) := '=';
actual_line VARCHAR2(150);
idx NUMBER := 1;

14
Introduction to PLlSQL

BEGIN
WHILE (idx<=line_1ength) LOOP
actua1_1ine := actua1_1ine I I separator;
idx := idx +1 ;
END LOOP;
DBMS_OUTPUT.PUT_LINE(actua1_1ine);
END;
/

The index of the WHILE LOOP must be dedared and initialized. The index
should be incremented programmatically. The condition is evaluated first, and if
it results to be TRUE, then only the body of the loop is executed. There's no need
for an explicit EXIT condition for the loop.

PL/SQL Environments
To develop and execute 3GL programs, you need a development environment in
which you can write and execute the programs. This is called an integrated devel-
opment environment, or IDE. Most popular 3GLs such as Java, C++, and so forth
provide such IDEs as IBM's Visual Age for Java, Visual C++, and so on.
There are typically three types of environments necessary for any program-
ming language, and PLlSQL is no exception:

1. Development environment

2. Execution environment

3. Debugging environment

Orade provides two major development environments for the development


and execution ofPLlSQL programs: SQL*Plus and Procedure Builder. These IDEs
not only enable development and execution, but they also assist in debugging
PLlSQL programs. However, the interface for each of these environments is dif-
ferent. Both are interactive, with Procedure Builder providing a greater degree of
debugging functionality.

15
Chapter 1

Figure 1-1 shows an example ofthe SQL*Plus environment.

)(

SOL Plu. R.I.a •• 9 2 eIe - Produetion on Hon Oet 1 21 : 31 . 19 2882

Copyr ght ( e ) 1982 . 288Z . Orael. Corporatlon All rlght. r •••ru.d .

Conn.et.d to :
Or.el.91 Ent.rprl" Edition R.l •••• 9 . 2 .8 1 8 - Produetlon
Wlth th. Partltl0nlng . OL P nd Orael. Data Hlnlng options
JS.ru.r R.I.ae. 9 2 eIe - Produetl0n

SOL ) e.t e.ru.rout on ;


SOL ) OECLARE
2 lln._l.ngth U ER :58 :
3 • parator UARCH RZ(I) ' :': ':
~ aetual_Iln. UARCH R2 ( 158) ;
5 BEGIN
6 FOR idx In 1 . lin._l.ngth LOOP
7 aetual_Iln.: etual_Iin. Ile.parator :
8 E 0 LOOP .
9 DBHS_OUTPUT . PUT_LI E( aetual_Iln.):
18 E D.
11 /
::::::::::::::::::::::::::::::::::::::::::::::::::

PL/SOL proeedur. euee ••• fully eo.pl.ted .

SOL > I

Figure 1-1. The SQL *Plus development and execution environment

Grade Procedure Builder is more of a GUI tool and has a more powerful
debugging capability than SQL*Plus. For instance, you can set breakpoints and
you can define the functions of step in, step into, and step out to debug a PLlSQL
subprogram. Figures 1-2 and 1-3 show the typical Procedure Builder develop-
ment and debugging environments, respectively. The debugging environment
has certain breakpoints to track the execution of pro grams. Breakpoints are
points of control in a PLlSQL pro gram where execution ofthe program pauses
and the user can interactively know the value of runtime variables and decide
whether to halt execution by stepping out of the pro gram or resume execution by
stepping into the code.

16
Introduction to PLlSQL

L> C1U:ATf: OR R&PUC& f line


hp 11n ienll h IN /. I:R.
AP:,~pat. O{ IN ~~)

ldx 1n l .. lp lln~ 1 ng h LOOP

Figure 1-2. The Procedure Builder development and execution environment

~ O,ne"! P,ncealurß ßuilder 11. t9i@arlu: 1 x


d., Voow Plo bu Window ~ Ip
-----~-
;;PI/SCI In10, "~1,,,

h LOOP
Illp_lIe.,.u Ot:

LIHI: 9

Figure 1-3. The Procedure Builder debugging environment

New Features of PL/SQL 9i


Anumber ofnewfeatures have been added to PLlSQL in Oracle9i. Some are new
features of the language itself, some are enhancements made to existing features,
and still others are added functionalitywith regard to how PLlSQL has been
implemented. This section presents in some detail the major new features of

17
Chapter 1

PLlSQL 9i and broadly categorizes them into two groupS: namely, non-object-
oriented features and object-oriented features. Details of each feature are
explained throughout the book.

Non-Object-Oriented Features Exclusive to PL/SQL 9i


In this section, I introduce the new non-object-oriented features of PLlSQL 9i
such as CASE statements and expressions, searched CASE statements and
expressions, cursor expressions, native compilation ofPLlSQL code, data manip-
ulation language (DML) operations (specifically, INSERT, UPDATE, and SELECT)
involving entire PLlSQL re cords (as of Oracle9 i Release 2), associative arrays (as
of Oracle9 i Release 2), new PLI SQL packages and enhancements to existing
packages, new SQL features in PLlSQL, and miscellaneous enhancements.

CASE Statement

Oracle9 i intro duces the CASE statement as an improved alternative to the IF ...
ELSIF ... statement. The use of CASE statement provides more compact code
and increased usability on the part of the programmer, and increased readability
on the part of the code reviewer. Here's the syntax of the CASE statement:

(ASE selector
WHEN valuel THEN actionl;
WHEN value2 THEN action2;
WHEN value3 THEN action3;

ELSE actionN;
END (ASE;

In the preceding code, selector is a variable or expression, and valuel,


value2, and value3 are the values of the selector. The selector is evaluated only
once. In the case of a CASE statement, this is immediately evident to the com-
piler, as the selector is specified only once in the beginning.
The order in which the WHEN branches are written is important, as it deter-
mines which one of the actions is to be executed.
Here's an example of a CASE statement:

(ASE report_choice
WHEN 1 THEN p_proc_reportl;
WHEN 2 THEN p_proc_report2;
WHEN 3 THEN p_proc_report3;

18
Introduction to PLlSQL

WHEN 4 THEN p_proc_report4;


ELSE dbms_output.put_line('Invalid option. ');
END (ASE;

In the preceding example, depending on the value ofthe reporcchoice vari-


able, the corresponding procedure is executed. The same code segment written
as an IF ... ELSIF chain would have the condition repeated for each choice, as
shownhere:

IF (report_choice=l) THEN
p_proc_reportl;
ELSIF (report_choice=2) THEN
p_proc_report2;
ELSIF (report_choice=3) THEN
p_proc_report3;
ELSIF (report_choice=4) THEN
p_proc_report4;
ELSE
dbms_output.put_line('Invalid option. ');
END IF;

This method is more error-prone than the CASE statement.

CASE Expression

You can use the CASE construct in an expression and assigned it to a variable to
generate a value. Here's the syntax of the CASE expression:

var := (ASE selector


WHEN valuel THEN assigned_valuel
WHEN value2 THEN assigned_value2
WHEN value3 THEN assigned_val ue3

ELSE assigned_valueN;
END (ASE;

In the preceding code, var is a declared variable that receives a value.


value 1, value2, and value3 are the values of the selector, and assigned_value 1,
assigned_value2, assigned_value3, and assigned_valueN are the values that are
assigned to the variable var depending on the value of the selector.
As an example, consider the following code segment, which is part of a pro-
gram that converts digits to words:

19
Chapter 1

temp (ASE i
WHEN o THEN 'Zero'
WHEN 1 THEN 'One'
WHEN 2 THEN 'Two'
WHEN 3 THEN 'Three'
WHEN 4 THEN 'Four'
WHEN 5 THEN 'Five'
WHEN 6 THEN 'Six'
WHEN 7 THEN 'Seven'
WHEN 8 THEN 'Eight'
WHEN 9 THEN 'Nine'
ELSE
NULL
END;

Searched CASE Statement

The searched CASE statement is a variant of the CASE statement and has no
selector defined. Instead of testing on the equality of the selector, the searched
CASE statement tests a boolean expression for a truth value. Here's the syntax of
the searched CASE statement:

(ASE
WHEN (boolean_condition1) THEN action1;
WHEN (boolean_condition2) THEN action2;
WHEN (boolean_condition3) THEN action3;

ELSE actionN;
END (ASE;

Here's an example of the previously presented CASE statement rewritten


using the searched CASE statement:

(ASE
WHEN (report_choice 1) THEN p_procJeport1;
WHEN (report_choice 2) THEN p_procJeport2;
WHEN (report_choice 3) THEN p_proc_report3;
WHEN (report_choice = 4) THEN p_procJeport4;
ELSE dbms_output.put_line('Invalid option. ');
END (ASE;

20
Introduction to PLlSQL

TIP Always specify the ELSE part explicitly when you use
a searched CASE statement.

Searched CASE Expression

The searched CASE expression is a variant of the CASE expression, and it omits
the selector. Like the searched CASE statement, it tests for the truth value of
a boolean condition instead of the equality of a single selector common for all
WHEN clauses. !t's used in assignment statements. Here's the example of the pre-
viously presented CASE expression rewritten using a searched CASE expression:

temp := (ASE
WHEN (i=O) THEN 'Zero'
WHEN (i=l) THEN 'One'
WHEN (i=2) THEN 'Two'
WHEN (i=3) THEN 'Three'
WHEN (i=4) THEN 'Four'
WHEN (i=S) THEN 'Five'
WHEN (i=6) THEN 'Six'
WHEN (i=7) THEN 'Seven'
WHEN (i=8) THEN 'Eight'
WHEN (i=9) THEN 'Nine'
ELSE
NULL
END;

Searched CASE expressions are more powerful than ordinary CASE


expressions because you can use them to evaluate multiple conditions involving
multiple variables rather than basing conditions on a single variable. For
instance, consider the example of comparing two numbers as greater than, less
than, or equal to that I presented earlier in the chapter when I covered IF
statements. You can implement this comparison more elegantly using a
searched CASE expression. Here's the corresponding code (you should set the
SERVEROUTPUT environment variable to ON before executing this code):

declare
a number 20;
b number -40;
string varchar2(SO);

21
Chapter 1

begin
string ca se
when (a>b) then 'A is greater than B'
when (a<b) then 'A is less than B'
else
'A is equal to B'
end;
dbms_output.put_line(string);
end;
I

Here's the output ofthis pro gram:

A is greater than B
PL/SQL procedure successfully completed.

Cursor Expressions

Oracle9 i has incorporated the facility to nest cursors in PLlSQL cursor declar-
ations in the form of cursor express ions. Cursor expressions eliminate the use of
declaring and using multiple cursors, and hence result in a more effective opti-
mization scheme by the SQL engine (only one SQL statement) than in the case of
multiple cursors (multiple SQL statements). Also, cursor expressions eliminate
the use of the complicated joins involved in SQL SELECT statements. As a third
benefit, Oracle9 i removes the limitation of using cursor expressions in SQL
embedded in PLlSQL code. Nowyou can use cursor expressions as part of
PLlSQL cursors. Also, when you use dynamic SQL, you can use and fetch cursor
expressions into REF cursor variables. In this case, they support the complex
binds and defines needed for REF cursors. This is not supported by DBMS_SQL.

CROSS-REFERENCE I discuss cursor expressions in detail in


Chapter 2.

22
Introduction to PLlSQL

Native Compilation of PLISQL Code

PLlSQL 9i allows native compilation of PLlSQL packages, procedures, and


functions, and the subsequent conversion to native C code and storage in
machine code. The PLlSQL is translated into C code rather than p-code, which is
in interpreted mode, and it's compiled using the C compiler on the given plat-
form and then linked directly into Orade processes. When the particular stored
subprogram is invoked, the natively compiled program is mapped to the
Pro gram Global Area (PGA). This native compilation of PLI SQL code is most
effective when you're writing compute-intensive PLlSQL subprograms that
perform database-independent tasks. In this case, native compilation results in
faster execution of PLlSQL.

DML Operations Involving Entire PLISQL Records

PLlSQL 9 i as of Orade9 i, Release 2 allows the INSERT and UPDATE operations


involving entire PLlSQL records. Instead of specifying a list of individual record
attributes, you can insert re cords into the database using a single variable of type
RECORD or %ROWTYPE. The same is allowed for the UPDATE operation. Also,
you can do bulk binding operations involving SELECT, FETCH, INSERT, UPDATE,
and RETURNING INTO using a single variable of type PLlSQL table of re cords
instead of specifying individual PLlSQL tables for each SQL column.

CROSS-REFERENCE I discuss enhancements related to DML


operations involving entire PL/SQL records further in
Chapter3.

Associative Arrays

In line with index-by tables, Orade9i Release 2 enables definition of index-by


tables that are indexed by VARCHAR2 values instead of BINARY_INTEGER. The
VARCHAR2 index serves as a primary key of a database table and improves per-
formance by enabling fast lookup of individual array elements, eliminating the
need for you to know the position of the individual element, and avoiding loop-
ing through all array elements.

23
Chapter 1

CROSS-REFERENCE I discuss associative arrays in detail in


Chapter3.

New PLISQL Packages and Enhancements to the Existing


Packages

PLlSQL 9 i incorporates a lot of new packages and provides enhancements to


existing packages. The new packages deserving mention are dbms_xmlgen,
which you use to create an XML document from any SQL query (in the form of
a character large object, or CLOB) , and dbms_metadata, which has the appli-
cation programming interface (API) for extracting complete definitions of
database objects in XML format or as SQL data definition language (DDL). Other
new packages are as follows:

dbms_transform

dbms_flashback

dbms_logmnccdc_publish

dbms_logmnccdc_subscribe

24
Introduction to PLlSQL

dbmsjedefinition

utLencode

In addition, Oracle9ihas three new special SQL data types that enable
dynamic encapsulation of and access to type descriptions, data instances, and
sets of data instances of any other SQL type, including object and collection
types. In addition, you can use these three special types to create anonymous
(i.e., unnamed) types, including anonymous collection types. The three special
types are SYS.ANYTYPE, SYS.ANYDATA, and SYS.ANYDATASET.
Of the enhanced packages, the UTL_FILE package, which provides the API
for file input! output (1/0), also has some enhancements with regard to enabling
opening, reading, and writing files in Uni code format. And as of Oracle9 i
Release 2, the UTL_FILE package has the API to read and write binary data and
perform functions on files such as autoflush, seek, delete, copy, and rename from
within PLlSQL. The UTL_HTTP package has new features to support authentica-
tion, cookies, and sending large messages and persistent connections.

New SQL Features Available in PL/SQL

The new SQL features, such as the new date/time data types TIMESTAMP and
INTERVAL (and their variants), the MERGE statement, and the nullif and
coalesce functions, are automatically available for use in PLlSQL 9i.
You can use TIMESTAMP with two variants such as TIMESTAMP WITH TIME
ZONE and TIMESTAMPWITH LOCAL TIME ZONE. TIMESTAMP offers ahigher
level of granularity in the time component in addition to the capability to deal
with time zones. You can use INTERVAL with two variants: INTERVAL YEAR TO
MONTH and INTERVAL DAYTO SECOND. Also, Oracle9ihas defined a set of
built-in functions associated with TIMESTAMP and INTERVAL, and you can
invoke all of these functions in PLlSQL.
The MERGE statement enables you to combine the insert and update
functions into a single operation.

25
Chapter 1

Miscellaneous Enhancements

Other new features (in addition to the ones I described in the previous sections)
that are significant to SQL and/ or PL/SQL performance and usability are as
follows:

• Integration oJthe SQL and PLlSQL parser: The integration of SQL and
PL/SQL is tighter with SQL and PL/SQL sharing a parser. This enables fea-
tures implemented in SQL to be automatically available in PL/SQL.

• Reduced overhead oJ calling PLlSQL subprograms from SQL: This enables


faster execution of SQL that references PL/SQL subprograms.

• Seamless integration oJCLOB with VARCHAR2: Assignment ofVARCHAR2


to CLOB and using string functions on CLOB and NCLOB are now possible
in PL/SQL 9i. Also, 9inow provides implicit data conversion between
VARCHAR2 and NVARCHAR2.

• Autogeneration oJPLlSQL call specs Jor Java stored procedures while loading
Java classes into the database: This feature is available as of Oracle9 i
Release 2. I discuss this feature further in Chapter 13.

Object-Oriented Features Exclusive to PL/SQL 9i


This section intro duces the new object-oriented features ofPL/SQL 9i, such as
bulk dynamic SQL and exception handling with bulk binding, pipelined table
functions, multilevel collections, object type inheritance and dynamic method
dispatch, and SQLJ object types and type evolution. It also presents the new fea-
ture of user-defined constructors and a new API to load large objects from
external files, which are introduced in Oracle9 i Release 2.

Bulk Dynamic SQL and Exception Handling with Bulk Binding

Oracle9iPL/SQL allows dynamic bulk binding, which is the use ofthe BULK
COLLECT construct for SELECT statements, the FORALL ... USING
construct for INSERT, and the UPDATE and DELETE statements with the
EXECUTE IMMEDIATE construct so that bulk binding can be done with native
dynamic SQL in PL/SQL. Dynamic bulk binding is also supported for implicit
query in a DML statement via the RETURNING keyword.

26
Other documents randomly have
different content
He was silent a moment, realizing there was nothing to be gained
by attempting to deceive her. How, when or where she learned of
these matters he never knew; but she knew perhaps more than he
did of what was happening in Fukui.
“Even if it is so,” he finally said, “and the samourai too are gone,
you have nothing to fear. Less than a week ago a courier brought
word to me from Tokio. I am expecting friends in Fukui very shortly
now.”
“Frien?” she repeated wistfully. “Like unto you, kind Tojin-san?”
“Yes—white men, and Japanese, too, for that matter. I have good
friends in Tokio. They are coming here to see you, my child.”
“Alas!” she said, shrinking slightly from him, “Why do they come?”
“I asked them to come,” he said, very gravely. “I feel I am right,
and that by a simple operation we will be able to make you see, as
other people do, my child.”
The word appeared to trouble her.
“I see already, Tojin-san,” she said.
“What do you see, Tama?” he asked her huskily.
The words came floodingly, tumultuously to her lips. The misty
eyes were blue as the sea and as beautiful.
“I see thee, Tojin-san. Thou art beautiful ad my sight, lig’ unto the
gods.”
A look of suffering left its mark upon the face of the Tojin. He
gazed at the kindling face of the girl before him, and the old
strangling, yearning emotion swept over him.
“Give me more sight—if it is your honorable wish,” she said, “bud
already I see—I know!” She pressed her fingers impetuously to her
eyes.
“I see the light—the dark. It is a worl’ of shadows on my eyes,
and shadows are lig’ unto our dream—mos’ beautiful of all!”
His voice was firm, almost solemn.
“You have been wandering around in a black wilderness all of your
life; you do not know what it is, my poor little one, to see the sun!
But, with God’s good help, I am going to lead you out of the
wilderness—into the light!”
“You are the light!” she said, throbbingly, and slipped to her
knees, putting her face against his hand.
Something bounded against the wall and came whistling through
the shoji. It grazed the cheek of the kneeling fox-woman, and
imbedded itself against the woodwork of the opposite wall. She put
up her hand with a quick, startled movement, but though she turned
a questioning, fearful face upon the great Tojin, she could not see
how deathly white he had become. He bent suddenly above her.
“Make me a promise. Repeat after me, that no matter what might
befall us, you will remain with me—you will not desert me!”
With her face pressed against his hand, her eyes fervently closed,
she repeated the words as a veritable prayer.
XVI

In the sunken garden directly beneath his rooms he saw that


sinister thing below, waiting in a throbbing silence. It seemed as if
his gardens were alive with them. Who had summoned them? For
what were they waiting?
From his elevation above them he spoke, his clear voice booming
out above their heads.
“Genji Negato, I desire your services.”
From somewhere in the shadows the voice of the interpreter came
back at him like a cold slap in the face.
“When the evil spirit of Atago Yama shall have left the abode of
the exalted Tojin-san, Genji Negato will humbly return for service.”
The Tojin-san’s incisive, perfectly controlled voice continued coldly:
“By command of the Prince of Echizen you are in my service. In
his name, I order you to control your foolish fears, or take the
consequences of your Prince’s displeasure.”
A strange voice, rumbling, sneering, responded to this statement.
Like a flash, upon the retort, came the Tojin’s ringing order to the
interpreter:
“Translate the words just spoken, if you please.”
“He says, your excellency, that the Prince of Echizen has been
summarily called to Tokio. If the new law is indeed enforced he may
not return.”
For a moment the far-seeing mind of the Tojin staggered before
this appalling news, which, if true, meant the possibility of his being
suddenly cast adrift and left to protect himself from the Jo-i menace,
against which Echizen himself had taken such precautions in his
behalf. While his mind revolved all the possible perils of his position,
a new voice sprang ringingly out of the shadows of his garden—a
boy’s clear, unfaltering voice with its reassuring note of loyalty and
affection.
“Beloved sensei, we, your students, offer ourselves in place of
your guard.”
“What may babes know of a sword’s honor?” snarled the
samourai, who had already spoken. “Upon what strength may the
foreign devil lean for his new support?” he demanded with cutting
sarcasm.
The burly laugh that followed was suddenly stopped, as the
student Higo flung himself defiantly before them all.
“I, Higo, kin of your absent Prince, will answer you. There are nine
hundred students, samourai themselves, and sons of a thousand
samourai before them. All of these are loyal to our teacher. They will
protect and fight for him, if necessary.”
Now the answering voice snarled merely in explanation.
“Who spoke of harm to your sensei? It is not him we seek. We
have come for the Fox-Woman of Atago Yama, who blights our
fortunes, who brings sickness, poverty, and disaster upon our
ancestors and our children, and whose doom has been spoken by
Fukui. You have trapped her, young sirs of the college, like any other
female beast of the woods. Let older, more experienced hands finish
your honorable work. There are those of us whose hands performed
a like service upon the debased parents of the gagama, and whose
palms itch now to mingle her blood with her sire’s. Let but the Tojin-
san eject this siren of the mountains, and we will be satisfied.”
“It cannot be done,” frantically cried the boy Junzo. “I myself have
touched the wretched, helpless one, and, as the gods in heaven
hear me, she is but—human, as ourselves!”
A roar of derision greeted the boy’s passionate outcry, and there
was a concerted movement toward where the Tojin-san stood
towering above them, his arms crossed, his keen, stern eyes
regarding them piercingly.
Some one pushed forward the interpreter, and the craven,
agitated fellow now faced his master. He made several ineffectual
efforts to speak, gulped at the lump which rose persistently in his
throat. Before him loomed the grim, sardonic face of this west-
countryman he had always inwardly feared and respected; behind
him the rabble of dissatisfied ronin.
Gasping, trembling, he repeated to the Tojin the verdict of the
mob. They called upon him to deliver into their hands the fox-
woman. Failing to do that, they would storm the Shiro and take her
by force. Whiningly, pleadingly, he begged his master to hurl from
his house the wretched spirit he was harboring.
To this demand the Tojin-san returned slowly, as though he
carefully chose his words, that if one hair upon the head of the one
he protected were touched, the whole Fukui should feel a vengeance
such as never had befallen it before. He, the Tojin-san—a citizen of a
mightier country than this—was the guest of one of their princes.
Not alone his friends at home, but those here—the very Emperor
himself, who had pledged himself publicly to uphold the new
enlightened laws, borrowed from the West—would avenge insult and
wrong done to him—the Tojin.
His answer, translated by Negato, raised a turmoil of angry
discussion, and that one who seemed to be the leader of the
company, sprang headlong forward, as if to show the way to those
who hesitated. He climbed half-way up the steps to where the Tojin
stood, and quick as a cat drew forward his swords.
Every eye was turned upon the Tojin-san. He was standing tautly
erect, his heavy, pugnacious chin thrust out. As the sword of the
samourai touched him he drew slightly backward, then with a swift,
merciless bound sprang headlong upon his assailant, his great white
fists flashing more vividly than the steel had done. Backward went
the samourai, his swords flying out of either hand. Without a cry, he
fell upon the grass path beneath.
And the Tojin-san was back in his place, facing them, waiting for
them, calm, still unmoved, but very terrible and mighty to look upon.
In the deadly silence that followed, the student Nunuki passed the
castle gates, followed by his valiant, stalwart little army of fellow-
students. They moved in a line steadily onward, spread out on all
sides and completely surrounded the house of the Tojin.
Ere the samourai could realize it they found themselves encircled
by an army four times their own in number. Their leader lay before
them, unmoving; and above them towered the grim, terrible figure
of this west-countryman, who represented in his gigantic person all
the power and strength they had come to know and superstitiously
believe belonged to the West.
One by one, they moved toward the gates, broke into smaller
groups, passing the long line of student warriors without a word or
sign of war.
Presently the Tojin moved a step lower down into the garden. He
stood a moment, staring frowningly at the still form lying at his feet.
Then slowly, unwillingly he stooped, and turned it over. A deep
breath escaped him. For a moment things swam dazedly before him,
for the white, agonized face upturned was that of the Daimio’s high
officer, the Samourai Gihei Matsuyama!
XVII

As a mother seeks a lost child, so the Tojin-san frantically scoured


every nook and corner of the Shiro Matsuhaira for the fox-woman.
In the interval in which he had faced that threatening, blood-
hungry mob, she had gone! He was torn with sick forebodings of the
fate that might have befallen her. That she had gone of her own free
will, he could not believe—no, not after the promise she had made
him!
And so, with his wound untended, his brain swimming in vertigo,
he staggered from room to room, until the morning dawned dim and
gray, and the sun crept over the horizon with its bright, hard eye.
Wild and haggard-eyed, shaking as though he were afflicted with
ague, he came finally back to his own chamber. Here his students
awaited him, eager to show him their good-will, to congratulate him
and gossip over the certain punishment that would overtake those
who had molested him. But he heard no word that they spoke, and
presently they seemed to realize that something was wrong with the
great Tojin, and they drew apart, whispering, and regarding him with
awed glances.
The maid, Obun, snivelling and shaking with fear, crept into the
vast, deserted kitchen and fell to putting it in order. In another wing
of the house the voice of the lately craven Genji Negato was heard,
and out along the road, loaded down with their belongings, trailed
the little caravan of menials, creeping humbly back to their old
employment.
Oh, these were dark, impoverished days for Fukui! Who could
refuse remunerative employment such as this? The honorably
enlightened students of the university had vanquished the
disgruntled, fighting ones; Samourai Matsuyama, their leader, was
desperately sick, shorn of his power, and deserted even by his
friends.
And the fox-woman was gone! No one knew how or when she had
gone. They told, in whispers, of her ghostly vanishing, and some
said the bottom-less lake of Matsuhaira, with its white, chilly lotus,
held a secret all its own. But “The Lotus tells no tales,” as the
proverb has it, and how should they know, and why should they care
whether the fiendish gagama, who had haunted their master for so
long, floated beneath the smiling water-flowers or not?
They gathered together, these gabbling, faithless servants, and
discussed ways and means to propitiate the Tojin-san. Following the
lead of Genji Negato, finally, they took their courage into their hands
and came to his apartment. Barely had they entered the room,
however, ere they fled again.
One look only at the distorted face was enough. Like a pack of
startled sheep they turned tail and fled from his presence, leaving
him once more alone, pacing and repacing, with staggering,
irregular steps, the floor, crunching his great hands together as if in
some mortal agony.
What weakness was this that robbed him of his manhood! What
anguish that pierced to his very marrow? Was this what the son of
the Daimio’s high officer had endured when he had followed the fox-
woman out into the mountains? Persistently, dazedly he thought of
Gihei Matsuyama, and he asked himself repeatedly why—why?
Suddenly it was clear—he knew why. He had killed the Daimio’s high
officer! With his own mighty hands he had killed the father of Gihei
Matsuyama!
A Chinese doctor, brought by the students Junzo and Higo,
examined him at a safe distance, and he said the foreign sensei was
afflicted with a malady of the brain.
Outside in the summer gardens, serious-eyed, grave-faced boys
looked at each other with startled glances, and in the city people
were telling in the streets of the dreadful punishments certain to be
meted out to those who had molested the guest of their absent
Prince; for word had, at last, come from Tokio that he had started on
his way back to Fukui.
The day with its sun and fragrance passed away unseen to the
great, blank-minded Tojin. But when the night came, with a
whispering breeze about the ancient Matsuhaira, he raised a
listening head.
As on that first night in Fukui, plainly, distinctly he heard the
fluttering, human knocking upon his shoji. Holding his breath,
treading on tiptoe, he found his way to the doors, drew them apart
and looked out into the dusky woods beyond. How his ears tingled
now, straining for that old caressing call:
“T-o-o—jin-san! Too-jin-san!”
Gently, softly, wooingly, he answered the fox-woman, breathing
her name into the still air about him:
“Tama! Tama!”
And, as on that other night, again he dropped down into the
garden. Over the green-clipped lawn he went, across the wing of the
moat, into the bamboo grove, and on and on into the beckoning,
luring woods of Atago Yama.
XVIII

To awaken on an afternoon in summer upon a bed of moss and


fragrant leaves; to rest tired, aching eyes upon a clear, pale sky,
which smiled divinely through interlacing boughs of towering pines
and hemlocks; to hear the whistling calls of the wood-birds; the
murmuring, sobbing laughter of some fairy brooklet close at hand;
to feel the touch of a fugitive gentle breeze upon one’s brow—this
was the fate of the Tojin-san!
For how long he could not have told he lay unmoving, staring
dreamily at the sky above him, a sense of contentment, of rest, of
comfort—such as one might feel after a long, exhausting race,
permeating his whole being.
Then suddenly upon his consciousness there stole another sense—
the dim, exquisite feeling of a loved presence close at hand, and he
raised himself slowly, weakly upon his elbow. It was like music in his
ears, that faint, caressing voice he had listened for for so many
days:
“To-o-jin-san! Goran nasai!” (august glance deign).
She was kneeling by his side, her questioning, wistful face
hovering above his own; her soft, timid little fingers touching his
brow, his eyes, his lips.
He felt himself falling backward again, as if in some delicious
swoon, from which there could be no awakening. Then like the dimly
remembered scenes of a vague dream, he seemed to recall a time
wherein he had wandered through some unending woods, seeking,
seeking! Now the dream had ended in this—this that was part of the
dream itself!
She stirred ever so slightly, and as if he feared she might vanish
by her mere stirring, he reached up the great, once mighty arms,
and sought to envelop her within them.
Her hair had the odor of the pine woods; upon her lips there was
the breath of some sweet incense. She remained passive within his
grasp, but presently her voice, with its tremulous tone of tears,
broke the spell between them—reached him with the gentle appeal
of a child distressed.
“Honorable water good for thirsty throat,” she said.
Now he released her, and she drew back to find the little cup
beside her. He let her raise his head and bring the cup to his lips,
and with his eyes still hungrily upon her he drank the water.
He was content merely to gaze at her, though it troubled him that
she no longer smiled. She said in a very stricken voice:
“August food also good for Tojin-san. Bud, alas! I god nudding bud
rice! Thas good enough for Tama—bud nod for you, Tojin-san.”
Even in his weakness he laughed joyously at the mere notion of
food fit for her being unfit for him, and at the sound of his low
laughter her face lighted up wonderfully.
“You gittin’ better!” she exclaimed joyously. “Now I bring you thad
rice. Too bad—bud thas all I got! I go ad grade temple at top those
hill. Priest too fat run quick to catch at me.” She laughed with an
element of her old mischievous defiance.
As he did not speak, too intent upon gazing at and marvelling on
the fairness of her face, her expression changed to one of melting
anxiety.
“I am lig’ unto those foolish karasu [crow], who mek chatter all
thad time. Condescend forgive me, Tojin-san. I nod speag agin
mebbe for—for twenty hour—yaes?”
No one had ever kissed her hands before. The sound, the touch
aroused her wonder, her apprehension. She drew her hands
instinctively from his, and for a moment held them up before her,
almost as if she looked at them. Then with an impetuous, laughing
little sob she thrust them back upon him:
“Do agin ad my hands, Tojin-san! I lig’ those,” she said.
It was not alone the pallor of bodily illness, but of some mental
pain that swept over his face, as he set the little hands back into her
lap, reverently, gently.
Later, when strengthened with the simple meal she made for him,
she told him how the night before she had come upon him in the
Atago Yama woods. It was but two days since the terrible events at
the Shiro had driven them both forth into this enchanted wilderness.
He had been ill but a night; yet it seemed to him many days.
No, she had not heard him calling her, nor had she called him.
This, too, was part of the dream; but something louder than any
human cry had reached her in her hiding-place in the mountains, the
intuitive, certain sense of the blind. She had retraced her steps down
the mountain-side, and had gone cautiously seeking in the woods for
him; and the gods had guided her aright. Ah! to his very feet.
She humbly begged him to pardon her for leaving him; but she
had thought this was the only way she could save him from those
who hated her. Now—now she wished to repeat the prayer and
promise she had made him down in the old Shiro. Never again would
she desert him. She would always abide by his side. She humbly
entreated that he would permit her to remain with him, even if she
must follow him throughout the world as a slave, the meekest and
lowliest of servants.
He did not reply, so obsessed was he still with the vision of her
loveliness. Throughout the golden afternoon he lay there watching
her every little movement, her slightest change of expression;
thrilling under the touch of her hands, the sound of her voice;
obeying her slightest request; permitting her to serve him as if he
were a babe and she his mother.
Gradually the murmuring of the crickets in the grass, the soft
chirping of the birds, even the babbling of the brook, the sighing of
the gentle breezes seemed to soften their tone to one concerted
murmuring lullaby. A veil crept gently over the sky, shutting out the
sun and its light.
She put a pillow of pine needles beneath his head, and she
covered him over with a downy, silken mantle that smelled of temple
incense and was gorgeous beyond words with the golden
embroidery of some sacred order.
And presently as he drowsed deliciously under the warm fragrant
silk, he felt her stirring at his feet, and her tired little voice came
whispering to him as if from very far away:
“Sayonara, Tojin-san! Imadzuka!” (Now we rest).
Welcome to Our Bookstore - The Ultimate Destination for Book Lovers
Are you passionate about books and eager to explore new worlds of
knowledge? At our website, we offer a vast collection of books that
cater to every interest and age group. From classic literature to
specialized publications, self-help books, and children’s stories, we
have it all! Each book is a gateway to new adventures, helping you
expand your knowledge and nourish your soul
Experience Convenient and Enjoyable Book Shopping Our website is more
than just an online bookstore—it’s a bridge connecting readers to the
timeless values of culture and wisdom. With a sleek and user-friendly
interface and a smart search system, you can find your favorite books
quickly and easily. Enjoy special promotions, fast home delivery, and
a seamless shopping experience that saves you time and enhances your
love for reading.
Let us accompany you on the journey of exploring knowledge and
personal growth!

ebookgate.com

You might also like