1. Trang chủ
  2. » Công Nghệ Thông Tin

Teach Yourself PL/SQL in 21 Days- P1

50 371 0
Tài liệu đã được kiểm tra trùng lặp

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

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

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề Teach Yourself PL/SQL in 21 Days
Tác giả Bradley L. Jones
Người hướng dẫn Chris Webb, Development Editor, Steve Rowe, Managing Editor, Lisa Wilson, Project Editor, Heather Talbot, Copy Editor, Kitty Jarrett, Indexer, Chris Wilcox, Proofreader, Megan Wade, Associate Publisher, Jeff Shockley, Technical Editor
Trường học Sams Publishing
Chuyên ngành PL/SQL Programming
Thể loại book
Năm xuất bản 2000
Thành phố Indianapolis
Định dạng
Số trang 50
Dung lượng 2,25 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Sams Teach Yourself PL/SQL  in21 Days, Second Edition Copyright ©2000 by Sams Publishing All rights reserved.. Contents at a GlanceIntroduction 1 Day 1 Learning the Basics of PL/SQL 7 2

Trang 1

A Division of Macmillan USA

800 Easty 96th St., Indianapolis, Indiana, 46240 USA

Teach Yourself

SECOND EDITION

Trang 2

Sams Teach Yourself PL/SQL  in

21 Days, Second Edition

Copyright ©2000 by Sams Publishing

All rights reserved No part of this book shall be reproduced, stored in aretrieval system, or transmitted by any means, electronic, mechanical, photo-copying, recording, or otherwise, without written permission from the publish-

er No patent liability is assumed with respect to the use of the informationcontained herein Although every precaution has been taken in the preparation

of this book, the publisher and author assume no responsibility for errors oromissions Neither is any liability assumed for damages resulting from the use

of the information contained herein

International Standard Book Number: 0-672-31798-2Library of Congress Catalog Card Number: 99-65434Printed in the United States of America

First Printing: December 1999

06 05 04 03 7 6 5 4

Trademarks

All terms mentioned in this book that are known to be trademarks or servicemarks have been appropriately capitalized Sams Publishing cannot attest tothe accuracy of this information Use of a term in this book should not beregarded as affecting the validity of any trademark or service mark

PL/SQL is a trademark of Oracle Corporation

Warning and Disclaimer

Every effort has been made to make this book as complete and as accurate aspossible, but no warranty or fitness is implied The information provided is on

an “as is” basis The authors and the publisher shall have neither liability norresponsibility to any person or entity with respect to any loss or damages arising from the information contained in this book

Trang 3

Contents at a Glance

Introduction 1

Day 1 Learning the Basics of PL/SQL 7

2 Writing Declarations and Blocks 33

3 Writing PL/SQL Expressions 63

4 Using Functions,IFStatements, and Loops 99

5 Implementing Loops and GOTOs 127

6 Using Oracle’s Built-In Functions 155

7 Procedures, Packages, Errors, and Exceptions 189

11 Writing Database Triggers 293

12 Using Oracle8i Objects for Object-Oriented Programming 333

13 Debugging Your Code and Preventing Errors 371

14 Leveraging Large Object Types 401

15 Managing Transactions and Locks 437

16 Generating Dynamic SQL 451

17 Writing to Files and the Display 483

18 Managing Database Jobs 509

19 Alerting and Communicating with Other Procedures: The

DBMS_ALERTandDBMS_PIPEPackages 531

20 PL/SQL and Java 559

21 Advanced Queuing 585

Trang 4

WEEK3 In Review 613

Trang 5

D AY 1 Learning the Basics of PL/SQL 7

What Is PL/SQL? 8

Why Learn PL/SQL? 9

SQL, SQL*Plus, PL/SQL: What’s the Difference? 9

SQL 9

PL/SQL 10

SQL*Plus 10

What You Need to Finish This Book 12

Getting Started with PL/SQL 13

PL/SQL Is Block Structured 13

Compiling and Executing a Simple Block 15

What About Some Output? 17

Alternatives to Retyping 18

Writing Your First Function 20

Finding Compilation Errors 21

Displaying the Function’s Return Value 23

Can Even This Simple Function Be Useful? 23

Executing PL/SQL Using Developer 2000’s Procedure Builder 24

Starting Procedure Builder 24

Creating the SS_THRESHFunction 26

Connecting to a Database 27

Using SQLPlus Worksheet 28

Executing a PL/SQL Block Using SQLPlus Worksheet 28

Summary 29

Q&A 30

Workshop 30

Quiz 31

Exercises 31

D AY 2 Writing Declarations and Blocks 33 Exploring Datatypes 34

VARCHAR2 35

CHAR 36

NUMBER 38

BINARY_INTEGER 41

Trang 6

DATE 44

BOOLEAN 45

LONG 46

RAW 46

LONG RAW 47

ROWID 47

UROWID 48

MSLABEL 48

Using Block Structure 49

Anonymous Blocks 49

Function and Procedure Blocks 51

Trigger Blocks 53

Nested Blocks 54

Nesting Functions and Procedures 55

Scope Rules 58

Summary 59

Q&A 60

Workshop 60

Quiz 60

Exercises 61

D AY 3 Writing PL/SQL Expressions 63 Understanding Operators, Expressions, and Conversions 64

Building Expressions with PL/SQL Operators 64

Arithmetic Operators 65

Comparison Operators 68

Logical Operators 76

String Operators 78

Using Comparison Operators with Strings 79

The Effect of Character Set on String Comparisons 79

The Datatype’s Effect on String Comparisons 79

The Effect of Case on String Comparisons 81

Use of Comparison Operators with Dates 82

Exploring Expressions 83

Expressions Defined 83

Operator Precedence 84

Types of Expressions 86

Null Values in Expressions 86

Converting Datatypes 92

Implicit Conversion 92

Explicit Conversion 94

Trang 7

Summary 95

Q&A 95

Workshop 97

Quiz 97

Exercise 97

D AY 4 Using Functions, IFStatements, and Loops 99 Exploring PL/SQL Functions 100

Defining Parameters: Formal and Actual 102

Return Types 105

Function Violations 105

Exception Handling 106

Creating a Stored Function 106

Finding Errors 108

TheNULLStatement 110

Why Use the NULLStatement? 110

How to Call a Function from PL/SQL with or Without Parameters 110

Invoker and Definer Rights 111

Using PL/SQL Statements 111

TheIFStatement 112

TheIF THEN ELSEStatement 113

Nested IF Statements 114

UsingIF ELSIF 117

NestedIFVersus ELSIF 118

Formatting IFStatements 118

Avoiding Common Mistakes When Using IF 119

Looping Statements 120

Reversing the Loop 122

Incrementing Through a Loop Differently 122

Summary 123

Q&A 124

Workshop 125

Quiz 125

Exercises 125

D AY 5 Implementing Loops and GOTOs 127 Exploring Labels and the GOTOStatement 128

Statement Labels 128

TheGOTOStatement 128

Scoping Rules for the GOTOStatement 129

An Example of the GOTOStatement in Action 133

Why Use the GOTOStatement? 133

Trang 8

WHILELoops 134

Examples of WHILELoops 134

TheEXITandEXIT WHENStatements 138

Examples Using EXITandEXIT WHEN 139

Using Labels and EXITStatements with Loops 142

SimpleLOOPs 143

Sample Simple LOOPs 144

Creating a REPEAT UNTILLoop 144

An Example of a Simulated REPEAT UNTILLoop 145

What Loop Should I Use? 146

Loop Guidelines 146

Style Tips for Loops 148

Recursion 149

Guidelines 149

Practicing Recursion 150

Why Use Recursion? 152

Summary 152

Q&A 153

Workshop 153

Quiz 153

Exercises 154

D AY 6 Using Oracle’s Built-In Functions 155 Comparing SQL Functions and PL/SQL Functions 156

The Major Categories of Functions 156

Experimenting with Functions 161

Using Conversion Functions 161

UsingTO_DATE 161

UsingTO_CHARfor Dates 166

UsingTO_NUMBER 168

Using TO_CHARfor Numbers 174

DATEFunctions 175

SYSDATE 175

TheTRUNCFunction 176

TheADD_MONTHSFunction 178

TheNEXT_DAYFunction 179

TheLAST_DAYFunction 181

TheMONTHS_BETWEENFunction 182

TheNEW_TIMEFunction 183

TheROUNDFunction 184

TheTRIMFunction 185

Trang 9

Summary 185

Q&A 186

Workshop 186

Quiz 186

Exercises 187

D AY 7 Procedures, Packages, Errors, and Exceptions 189 Using Procedures 190

Why Use Procedures? 190

Procedures Versus Functions 190

Creating Procedures 190

TheRETURNStatement 192

Procedure Dependencies 192

Recompiling Stored Procedures 193

Re-creating and Modifying Procedures 194

Invoking Stored Procedures 194

Using Parameters 195

Parameter Definitions 195

Listing Stored Procedure Information 195

Dropping a Stored Procedure 197

Overloading Procedures 197

Using Recursive Procedures 197

Procedure Invocation Security 198

Exploring Packages 199

Why Use Packages? 199

The Package Specification 200

The Package Body 201

Creating Packages 202

Calling Package Subprograms 203

Recompiling Packages 204

Private Versus Public Package Objects 205

Package Invocation Security 205

Variables, Cursors, and Constant Persistence 205

Package States 205

Package Dependency 206

Trapping Errors and Exceptions 206

Exception-Handling Structures 207

SQLCODEandSQLERRM 211

Continuing Processing After an Exception 212

Retrying After an Exception 213

Re-raising Exceptions 213

Exception Scope Rules 214

Propagating Exceptions 214

Trang 10

Summary 215

Q&A 215

Workshop 215

Quiz 215

Exercises 216

WEEK1 In Review 217 WEEK2 At a Glance 219 D AY 8 Using SQL 221 Types of SQL DML Statements 223

Creating Some Oracle Tables 223

Using the INSERTStatement 226

Inserting Some Data 227

SingletonSELECTStatement 229

SomeSELECTCommand Examples 229

Exploring the UPDATEandDELETEStatements 230

Handling Types of Exceptions 232

Using the LOCK TABLEStatement 233

Transaction Control Statements 234

Using Records 234

Declaring a Record Variable 234

Using the %TYPEAttribute 235

Using Record Variables Based on Database Tables 236

Using Record Variables and SELECTStatements 237

Using Record Variables Based on Cursor Definitions 239

Declarations at the Package Level 240

Pseudocolumns 241

CURRVALandNEXTVALPseudocolumns 241

ROWIDPseudocolumns 242

ROWNUMPseudocolumns 242

Summary 242

Q&A 243

Workshop 243

Quiz 243

Exercises 243

D AY 9 Manipulating Data with Cursors 245 What Is a Cursor? 245

Explicit Cursors 246

Declaring a Cursor 246

Declaring Cursor Parameters 248

Trang 11

Opening the Cursor 248

Fetching Data in a Cursor 250

Closing the Cursor 251

Explicit Cursor Attributes 251

Explicit Cursor Example 253

Automated Explicit Cursors 253

Implicit Cursors 254

Implicit Cursor Attributes 254

Scope of Cursor Parameters 256

Cursor Return Clause and Packages 256

Cursor Variables 257

The Cursor Variable Declaration 257

Cursor Usage with Cursor Variables 258

Cursor Variable Assignments 260

Cursor Variables as Arguments 260

The Current Row of Cursors 261

Cursor Scoping 262

Cursor Alias 263

Summary 263

Q&A 263

Workshop 264

Quiz 264

Exercise 264

D AY 10 Collections 265 Using PL/SQL Index-by Tables 266

Declaring an Index-by Table 266

Inserting Entries into an Index-by Table 267

Referencing Values in an Index-by Table 268

Changing Table Entries 270

Deleting Table Entries 270

PL/SQL Table Methods 271

Using Nested Tables 274

Declaring a Nested Table 275

Adding Entries to a Nested Table 275

Removing Entries from a Nested Table 279

Using Variable-Sized Arrays 281

Declaring and Initializing a Varray 282

Adding and Removing Data from a Varray 283

Taking Advantage of Bulk Binding 284

UsingBULK COLLECT 285

UsingFORALL 286

Trang 12

Exception Handling for Collections 288

Summary 289

Q&A 289

Workshop 290

Quiz 290

Exercise 291

D AY 11 Writing Database Triggers 293 What Is a Trigger? 294

DML Triggers 294

An Example of a DML Trigger 295

Types of DML Triggers 296

The Syntax for Defining a Database Trigger 298

Uses for Triggers 300

Maintaining Data Integrity 300

Maintaining History 304

Managing Triggers 307

Listing Triggers 308

Viewing Trigger Code 309

Enabling and Disabling Triggers 310

Nontraditional Triggers 311

The Syntax for Defining a Trigger on a Database or Schema Event 312

Event Attributes 313

Writing a Trigger for a Database Event 314

Writing a Trigger for a DDL Event 316

Using Instead-of Triggers 318

The Syntax for Defining an Instead-of Trigger 318

Writing an Instead-of Trigger 319

Exploring Trigger Limitations 320

Triggers and Mutating Tables 320

Summary 329

Q&A 329

Workshop 330

Quiz 330

Exercises 331

D AY 12 Using Oracle8i Objects for Object-Oriented Programming 333 A Brief Primer on Object-Oriented Programming 334

Encapsulation 334

Inheritance 335

Polymorphism 335

Classes, Objects, Attributes, and Methods 336

Advantages of OOP Over Traditional Methods 336

Trang 13

How Oracle8i Implements Objects 337

Object Types 337

Object Tables 337

Object Views 337

Defining an Object Type 337

Constructor Methods 341

Accessor Methods 342

Mutator Methods 342

Instantiating and Using Objects 343

Storing and Retrieving Objects 345

Storing Objects as Table Columns 345

Retrieving and Updating Objects in a Table Column 347

Using Object Tables 349

Storing Objects in an Object Table 351

Retrieving and Updating Objects in an Object Table 352

Deleting Objects from an Object Table 356

Nesting and Sharing Objects 356

Dot Notation 356

Object References 358

Exploring the SELFParameter 361

Overloading 363

Comparing Objects 363

TheORDERMethod 364

TheMAPMethod 366

Limitations of Oracle’s Implementation 367

Summary 367

Q&A 368

Workshop 369

Quiz 369

Exercises 369

D AY 13 Debugging Your Code and Preventing Errors 371 Locating and Eliminating Syntax Errors 372

Identifying Syntax Errors 372

An Example of Identifying Syntax Errors .373

Preventing Syntax Errors 377

Handling Logic Errors 378

Order of Operations 379

Nonterminating Loops 380

Debugging Approaches for Logic Errors 380

Using Tools to Help in Debugging a Program 384

UsingDBMS_OUTPUTas a Debugging Tool 385

Writing a DEBUGPackage 385

Trang 14

Preventing Errors and Planning for Debugging in the Future 391

Defining Requirements and Planning Projects 391

Using a Modular Approach to Coding 392

Commenting Code 392

Writing Assertions into Code 394

Formatting Code 395

Summary 398

Q&A 398

Workshop 399

Quiz 399

Exercises 400

D AY 14 Leveraging Large Object Types 401 Exploring Large Object Datatypes 402

Limitations of LOBs 402

LOBVersus LONGDatatypes 403

Converting LONGs to LOBs 404

Using External Files in an Oracle8i Database 404

Creating the Directory Object 404

Limitations of BFILE 405

Using the DBMS_LOBPackage with BFILE 406

TheBFILENAMEFunction 406

TheCOMPAREFunction 407

TheFILECLOSE Procedure 408

TheFILECLOSEALLProcedure 408

TheFILEEXISTSFunction 408

TheFILEGETNAMEProcedure 409

TheFILEISOPENFunction 409

TheFILEOPENProcedure 410

TheGETLENGTHFunction 410

TheINSTRFunction 410

TheREADProcedure 411

TheSUBSTRFunction 411

ExploringBFILEExamples, Using the DBMS_LOBPackage 412

AccessingBFILEs 412

Comparing Files 414

Working with Locators 416

Using the DBMS_LOBPackage with Internal LOBs 416

TheAPPENDProcedure 417

TheCOMPAREFunction 417

TheCOPYProcedure 418

TheEMPTY_BLOBFunction 419

TheEMPTY_CLOBFunction 419

TheERASEProcedure 419

Trang 15

TheGETLENGTHFunction 420

TheINSTRFunction 420

TheREADProcedure 421

TheSUBSTRFunction 421

TheTRIMProcedure 422

TheWRITEProcedure 422

Exploring Internal LOBExamples, Using the DBMS_LOBPackage 423

Creating a Table 423

Adding Data to the Table 423

Populating the LOBSTable with the COPYProcedure 424

Manipulating Internal LOBs by Using APPENDandWRITE 425

Analyzing the Contents of an Internal LOB 427

UsingTRIMandERASEto Edit CLOBs 428

Temporary LOBs 430

Managing Temporary LOBs 430

Creating Temporary LOBs 430

Summary 431

Q&A 431

Workshop 432

Quiz 432

Exercise 432

WEEK2 In Review 433 WEEK3 At a Glance 435 D AY 15 Managing Transactions and Locks 437 Types of Transactions 438

Starting a Transaction 438

Ending a Transaction 439

Canceling a Transaction 441

Exploring the Two-Phase Commit 441

Creating Bookmarks with Savepoints 442

Using Release Option 443

Using Locking 443

Locking Tables 443

Locking Rows 445

Explicit Locks 445

TheDBMS_LOCKPackage 446

Using Other Locks 449

Monitoring Locks 449

Trang 16

Summary 450

Q&A 450

Workshop 450

Quiz 450

Exercise 450

D AY 16 Generating Dynamic SQL 451 What Is Dynamic SQL and Why Use It? 452

Two Approaches to Dynamic SQL 452

Using the DBMS_SQLPackage 453

Using the DBMS_SQLPackage with Non-Query DDL and DML Statements 454

Using the DBMS_SQLPackage with Queries 460

Using the DBMS_SQLPackage with Anonymous PL/SQL Blocks 467

DBMS_SQLError Handling 471

UsingLAST_ROW_COUNT 471

UsingLAST_ROW_ID 471

UsingLAST_ERROR_POSITION 474

Using Native Dynamic SQL 474

Executing DML and DDL 474

Executing SQL Queries 476

Executing PL/SQL Blocks 479

Summary 480

Q&A 480

Workshop 481

Quiz 481

Exercise 481

D AY 17 Writing to Files and the Display 483 Exploring the DBMS_OUTPUTPackage 484

Enabling the DBMS_OUTPUTPackage 484

Disabling the DBMS_OUTPUTPackage 485

Writing Data to the Buffer 486

Reading Data from the Buffer 487

Exceptions Raised from the DBMS_OUTPUTPackage 491

Reading and Writing Files with the UTL_FILEPackage 491

File Input 492

UsingUTL_FILEProcedures and Functions 493

An Example of Using UTL_FILE 500

ExploringTEXT_IOwith Client Files 504

Summary 506

Q&A 506

Workshop 507

Quiz 507

Exercise 507

Trang 17

D AY 18 Managing Database Jobs 509

Submitting Jobs by Using the DBMS_JOBPackage 510

Using Background Processes 510

Executing Jobs 512

Submitting Jobs to the Job Queue by Using SUBMIT 512

UsingRUNto Execute Jobs Immediately 514

Exploring the Job Environment 515

Viewing Jobs 517

Samples for Viewing Jobs 519

Exploring Job Management 519

Removing a Job 520

Altering a Job 520

Importing and Exporting Jobs 521

Handling Broken Jobs 521

Hands-on Practice in Job Management 522

Creating Procedures to Submit as Jobs 522

Submitting All Jobs to the Job Queue 524

Running All Three Jobs Immediately 524

Viewing Information About the Jobs 525

Altering the Job by Running the HELLOJob 525

Removing the Hello Job 526

Summary 528

Q&A 528

Workshop 529

Quiz 529

Exercises 529

D AY 19 Alerting and Communicating with Other Procedures: TheDBMS_ALERTandDBMS_PIPEPackages 531 TheDBMS_ALERTPackage 532

UsingSIGNALto Issue an Alert 533

Registering for an Alert 533

Waiting for a Specific Alert 534

Waiting for Any Registered Alert 535

Removing One Alert 535

Removing All Alerts 536

Polling and Events with the SET_DEFAULTSProcedure 536

Demonstrating the DBMS_ALERTPackage 536

Creating the Backup Database 537

Creating the Trigger to Signal an Alert 538

Waiting for the Alert 539

TheDBMS_PIPEPackage 543

Public Versus Private Pipes 543

Using Pipes 544

Trang 18

The Functions and Procedures of DBMS_PIPE 546

An Example of Using Pipes 550

Other Pipe Functions and Procedures 553

Other Uses for Pipes 555

Alerts Versus Pipes 555

Summary 556

Q&A 556

Workshop 557

Quiz 557

Exercises 558

D AY 20 PL/SQL and Java 559 Using Oracle’s Java Engine 560

Will PL/SQL Go Away? 561

Creating a Java Procedure 561

Prerequisites Needed 561

TheSS_CONSTANTSClass 562

Loading the Class 563

Publishing the SSThreshMethod 565

CallingSS_THRESHfrom SQL*Plus 566

CallingSS_THRESHfrom PL/SQL 567

Dropping the SSConstantsClass 568

Calling Java from PL/SQL 569

TheEmployeeClass 569

Publishing a Java Method 571

Datatype Compatibility 574

Using the OUTandIN OUTArguments 575

Calling PL/SQL from Java Using SQLJ 578

Using SQLJ to Execute an Anonymous PL/SQL Block 578

Using SQLJ to Call a PL/SQL Procedure or Function 579

Summary 582

Q&A 583

Workshop 583

Quiz 584

Exercise 584

D AY 21 Advanced Queuing 585 What Is AQ? 586

Removing Some of the Mystery from AQ 586

Key Features of AQ 587

Configuring Your Server to Use AQ 588

Exploring an AQ Scenario 590

Creating a Message Queue 591

Trang 19

Defining a Type for the Payload 591

Creating the Queue Table 592

Creating the Queue 595

Starting and Stopping a Queue 597

Placing Messages in a Queue 598

Enqueue-Related Record Types 599

Enqueuing a Message 602

Retrieving Messages from a Queue 604

Dequeue-Related Record Types 604

Dequeuing a Message 606

Using Other AQ Procedures .608

Dropping a Queue 608

Dropping a Queue Table 609

Granting and Revoking Access to a Queue 609

Summary 610

Q&A 611

Workshop 611

Quiz 611

Exercises 612

Trang 20

About the Authors

Jonathan Gennick is a manager in KPMG Consulting’s Public Services practice, where

he specializes in Oracle technologies He got his start with relational database systems in

1990, first working with Ingres, and then later with Digital’s Rdb software In 1994 he made the leap to Oracle, and hasn’t looked back yet Much of his time is spent providing database administration services, as well as server-side PL/SQL support, to clients and internal project teams.

When he is not working with Oracle, Jonathan can often be found writing about it Since

1997 he has been involved with a number of writing projects He coauthored the first

edition of this book, Sams Teach Yourself PL/SQL in 21 Days He was the technical tor for Oracle8 Server Unleashed (Sams, 1998), and the development editor for Sams

edi-Teach Yourself Access 2000 in 24 Hours (Sams, 1999) His second book, SQL*Plus, The Definitive Guide, was published in 1999 by O’Reilly & Associates In addition to

coauthoring the second edition of this book, Jonathan continues to be involved in various other writing and editing projects.

Writing has given Jonathan the opportunity to pursue several interests outside his normal day-to-day work He is a member of the technology committee for the Greater Lansing Adventist School, where he is currently helping to set up both a LAN and an Internet connection This satisfies his gnawing need to learn new things, and also his desire to help others learn.

Jonathan is a member of MENSA, and he holds a bachelor of arts degree in information and computer science from Andrews University in Berrien Springs, Michigan Jonathan resides in Lansing, Michigan, with his wife, Donna, and their two children, Jenny and Jeff Jonathan can be contacted by email at jonathan@gennick.com.

Tom Luers, PMP, is a principle consultant with a leading international information

tech-nology consulting firm Over the past 16 years, he has worked with clients and business partners in Europe, North America, and Asia Tom specializes in Project Management, Oracle technologies, and implementing IT solutions to meet business, manufacturing,

and engineering needs He is also the author of Sams Publishing’s Essential Oracle7.

Trang 21

To my daughter, Jenny You suffered without me while I wrote the first edition of this book, and now you’ve suffered again while I’ve written the second edition Thanks for being so patient I love you I’m very proud of you, and now I owe you another

First, I would like to thank Tom Luers for helping me to coauthor this second edition of

Sams Teach Yourself PL/SQL in 21 Days Both of us have worked hard on this revision.

Tom is a pleasure to work with, and with his client-side PL/SQL experience, he brings a valuable perspective to the book.

I would also like to thank Chris Webb of Macmillan USA for working so hard on his end

to make this project a reality Steve Rowe, also of Macmillan, put a lot of effort into ing this book, and deserves a big piece of the credit for the final result I’ve always felt that editors’ names should go on the front cover with the authors’ My appreciation also goes out to Jeff Shockley and Meggo Barthlow Jeff Shockley was the technical editor on this book He not only tested all the scripts to be sure that they worked on systems other than our own, but also provided valuable feedback on the clarity of our explanations Meggo Barthlow, of Macmillan, handled the large number of administrative details that

edit-go with the writing of any book.

Finally, I don’t want to forget my family and my readers To all the readers of the first edition who took the time to write in with questions, corrections, and other observations,

I say thanks! Your emails helped shape this revision Please keep the emails coming—I enjoy hearing from you To my family also, I must say thanks In fact, that just doesn’t cut it, but I don’t know what else to say My wife Donna has been incredibly patient and supportive while I’ve worked on this project There were many days when all I did from dawn to dusk was sit in my room and write Thanks, Donna! To my son Jeff: Thanks for always running in and interrupting me with a hug whenever you were in trouble with Donna To my daughter Jenny: Thanks for all those times that you let me drive you back and forth to school I’ll miss that when you’re older.

—Jonathan Gennick

Trang 22

I wish to thank my great wife, Cathy, and my great kids, Jon, Sarah, and Matthew Without their support, patience, and dedication, this project would not have been possi- ble I also wish to acknowledge the LSO sports organization, Thunderhawks, friends and family, and KI for providing many hours of relief for me and my family while working

on this project I wish to also thank Dad, Sis, Dee, and others for the special memories of them, which helped motivate me to complete this project.

—Tom Luers

Trang 23

Tell Us What You Think!

As the reader of this book, you are our most important critic and commentator We value

your opinion and want to know what we’re doing right, what we could do better, what areas you’d like to see us publish in, and any other words of wisdom you’re willing to pass our way.

As an associate publisher for Sams, I welcome your comments You can fax, email, or write me directly to let me know what you did or didn’t like about this book—as well as what we can do to make our books stronger.

Please note that I cannot help you with technical problems related to the topic of this book, and that due to the high volume of mail I receive, I might not be able to reply to every message.

When you write, please be sure to include this book’s title and authors as well as your name and phone or fax number I will carefully review your comments and share them with the authors and editors who worked on the book.

Fax: 317-581-4770 Email: adv_prog@mcp.com

Mail: Associate Publisher

Sams Publishing

800 Easty 96th Street Indianapolis, IN 46240 USA

Trang 25

Welcome to Sams Teach Yourself PL/SQL in 21 Days, Second Edition The fact that you

purchased this book indicates that you have an interest in learning the PL/SQL language, which is Oracle’s relational database procedural programming language It allows you to develop powerful and complex programs to access and manipulate data in the Oracle8i database We have attempted to include as many examples of PL/SQL code as possible to illustrate PL/SQL features.

This book is organized to teach you the major components of Oracle’s procedural language in

21 days, a chapter per day Each chapter covers a specific topic in PL/SQL and should take approximately three to five hours to complete (Of course, this time depends on your own pace.) This book introduces you to concepts and practical applications of them in PL/SQL programs We strongly encourage you to practice what you read Go ahead and type in the listings in your local Oracle database and experience PL/SQL for yourself You will gain a much deeper understanding of PL/SQL by practicing as you go along Feel free to experi- ment on your own with any concepts presented because this will reinforce what you learn.

We have made several assumptions about you, the reader We have assumed that you are

at least somewhat familiar with SQL and the Oracle database You should understand how to write simple SELECT,INSERT,UPDATE, and DELETEstatements Additionally, you should have some knowledge about Oracle database objects such as tables, as well as other schema objects such as sequences and views If needed, you might want to read

Sams Teach Yourself SQL in 21 Days prior to reading this book We have also assumed

that you want to learn some practical applications of PL/SQL and not just the syntax of the language Therefore, we have incorporated examples and notes to meet this goal.

What This Book Is About

The beginning of this book lays the foundation on which you will build PL/SQL grams In the first week, you will discover the building blocks of PL/SQL, such as expressions, various iterations, built-in functions, procedures, and error-handling rou- tines After this foundation is built, in the second week, you will move directly to learn- ing about more advanced PL/SQL topics, such as how to build PL/SQL programs with cursors processing, collections, triggers, composite database structures, debugging pro- cessing, and large object data types Finally, the third week covers transaction manage- ment, dynamic SQL, the Java engine, and advanced queuing When you complete this book, you will be able to develop your own PL/SQL programs You will have the knowl- edge to store these programs in the database and execute them.

Ngày đăng: 07/11/2013, 20:15

TỪ KHÓA LIÊN QUAN