iii Contents Volume 1 Preface xi Profile xii . Related Publications xviii Typographic Conventions xix I Introduction IĆ1 . Course Objectives IĆ3 Course Outline IĆ5 . The Relational Database Concept IĆ9 System Development Cycle IĆ17 What Is Oracle? IĆ19 The Oracle Product Set IĆ21 SQL, SQL*Plus, and PL/SQL IĆ23 . Summit Sporting Goods Demonstration Tables IĆ29 . Summary IĆ33 1. Selecting Rows 1Ć1 Objectives 1Ć3 . The Basic Query Block 1Ć5 Arithmetic Expressions 1Ć13 Column Aliases 1Ć21 The Concatenation Operator 1Ć23 . Literal Character String 1Ć25 Managing Null Values 1Ć27 . Preventing the Selection of Duplicate Rows 1Ć31 SQL*Plus Commands 1Ć35 . Logging in to SQL*Plus 1Ć37 . Displaying Table Structure 1Ć39 . SQL*Plus Editing Commands 1Ć41 SQL*Plus File Commands and Online Help 1Ć43 Creating a Report 1Ć45 . Summary 1Ć51 Practice Overview 1Ć53 Practice 1 1Ć55 2. Limiting Selected Rows 2Ć1 Objectives 2Ć3 . Ordering Rows with the ORDER BY Clause 2Ć5 Limiting Selected Rows with the WHERE Clause 2Ć11 Comparison Operators 2Ć13 iv Negating Expressions 2Ć17 . SQL Operators 2Ć19 . Querying Data with Multiple Conditions 2Ć27 Rules of Precedence 2Ć29 Summary 2Ć33 Practice Overview 2Ć35 Practice 2 2Ć37 3. Single Row Functions 3Ć1 Objectives 3Ć3 . Overview 3Ć5 Single Row Functions 3Ć7 . Character Functions 3Ć9 Number Functions 3Ć17 Oracle Date Format 3Ć23 . Using Arithmetic Operators with Dates 3Ć25 Date Functions 3Ć27 . Conversion Functions 3Ć33 . TO_CHAR Function with Date Formats 3Ć35 TO_CHAR Function with Number Formats 3Ć45 . TO_NUMBER and TO_DATE Functions 3Ć49 Nesting Single Row Functions 3Ć51 Nesting Functions 3Ć53 Summary 3Ć55 Practice Overview 3Ć57 Practice 3 3Ć59 4. Displaying Data from Multiple Tables 4Ć1 Objectives 4Ć3 . Overview 4Ć5 What Is a Cartesian Product? 4Ć7 Simple Join Query 4Ć9 Using Table Aliases 4Ć17 . NonĆEquijoin 4Ć19 . Returning Records with No Direct Match 4Ć21 . Joining a Table to Itself 4Ć25 Summary 4Ć27 Practice Overview 4Ć29 Practice 4 4Ć31 5. Group Functions 5Ć1 . Objectives 5Ć3 . Overview 5Ć5 Group Functions 5Ć7 . v The GROUP BY Clause 5Ć13 Illegal Queries Using Group Functions 5Ć19 Groups Within Groups 5Ć23 The HAVING Clause 5Ć25 Summary 5Ć31 Practice Overview 5Ć33 Practice 5 5Ć34 6. Subqueries 6Ć1 Objectives 6Ć3 . Overview 6Ć5 Subqueries 6Ć7 How Are Nested Subqueries Processed? 6Ć9 Single Row Subqueries 6Ć11 Errors with Subqueries 6Ć15 Multiple Row Subqueries 6Ć17 HAVING Clause with Nested Subqueries 6Ć19 Summary 6Ć21 Practice Overview 6Ć23 Practice 6 6Ć25 Volume 2 7. Specifying Variables at Runtime 7Ć1 Objectives 7Ć3 . Overview 7Ć5 Substitution Variables 7Ć7 . Single Ampersand Substitution Variables 7Ć9 Defining User Variables 7Ć15 Passing Values into a Script File 7Ć21 Summary 7Ć23 Practice Overview 7Ć25 Practice 7 7Ć26 8. Overview of Data Modeling and Database Design 8Ć1 Objectives 8Ć3 . Overview 8Ć5 System Development Cycle 8Ć7 Database Design 8Ć9 . Data Model 8Ć11 Entity Relationship Modeling 8Ć13 . Entity Relationship Model Concepts 8Ć15 . Integrity Constraints and Keys 8Ć23 Designing the Database 8Ć29 . Summary 8Ć39 vi 9. Creating Tables 9Ć1 Objectives 9Ć3 . Overview 9Ć5 Creating Tables 9Ć7 . Oracle7 Datatypes 9Ć13 Constraints 9Ć15 Creating a Table from a Table Instance Chart 9Ć25 . Creating a Table from Rows in Another Table 9Ć31 . Confirming Table Creation 9Ć33 . Summary 9Ć35 Practice Overview 9Ć37 Practice 9 9Ć39 10. Oracle Data Dictionary 10Ć1 . Objectives 10Ć3 . Overview 10Ć5 Querying the Data Dictionary 10Ć7 . Checking Constraints on a Table 10Ć13 . Summary 10Ć17 Practice Overview 10Ć19 Practice 10 10Ć21 11. Manipulating Data 11Ć1 . Objectives 11Ć3 . Overview 11Ć5 Adding a New Row to a Table 11Ć7 Copying Rows from Another Table 11Ć19 Updating Rows 11Ć21 . Deleting Rows 11Ć29 Transaction Processing 11Ć35 Committing Changes 11Ć39 . Rolling Back Changes 11Ć43 . Rolling Back Changes to a Savepoint 11Ć45 . Statement Level Rollback 11Ć47 Summary 11Ć49 Practice Overview 11Ć51 Practice 11 11Ć53 12. Altering Tables and Constraints 12Ć1 . Objectives 12Ć3 . Overview 12Ć5 Adding a Column 12Ć7 . Modifying a Column 12Ć9 Adding and Dropping a Constraint 12Ć11 vii Disabling and Enabling a Constraint 12Ć15 Dropping a Table 12Ć17 . Renaming and Truncating a Table 12Ć19 Adding a Comment to a Table 12Ć21 Summary 12Ć23 Practice Overview 12Ć25 Practice 12 12Ć27 13. Creating Sequences 13Ć1 . Objectives 13Ć3 . Overview 13Ć5 Creating a Sequence 13Ć7 Using a Sequence 13Ć13 Altering a Sequence 13Ć17 Removing a Sequence 13Ć19 Summary 13Ć21 Practice Overview 13Ć23 Practice 13 13Ć25 14. Creating Views 14Ć1 Objectives 14Ć3 . Overview 14Ć5 Creating a View 14Ć7 Performing DML Operations on a View 14Ć15 Confirming View Names and Structures 14Ć21 . Removing a View 14Ć23 . Summary 14Ć25 Practice Overview 14Ć27 Practice 14 14Ć29 15. Creating Indexes 15Ć1 Objectives 15Ć3 . Overview 15Ć5 When Is the Index Used? 15Ć7 Index Structure 15Ć9 . Creating an Index 15Ć13 . Confirming Indexes 15Ć17 . Removing an Index 15Ć19 . Summary 15Ć21 Practice Overview 15Ć23 Practice 15 15Ć25 16. Controlling User Access 16Ć1 . Objectives 16Ć3 . Overview 16Ć5 viii System Privileges 16Ć7 . What Is a Role? 16Ć11 Changing Your Password 16Ć13 Granting Object Privileges 16Ć15 . Confirming Privileges Granted 16Ć21 Revoking Object Privileges 16Ć23 Creating a Synonym for an Object 16Ć25 Summary 16Ć29 Practice Overview 16Ć31 Practice 16 16Ć33 17. Summary of SQL and SQL*Plus 17Ć1 Summary of SQL and SQL*Plus 17Ć3 Practice Overview 17Ć9 Practice 17 17Ć11 Volume 3 18. Overview of PL/SQL 18Ć1 . Objectives 18Ć3 . Overview 18Ć5 PL/SQL Block Structure 18Ć9 . The PL/SQL Environment 18Ć15 About Procedure Builder 18Ć17 19. Basics of Procedure Builder 19Ć1 Objectives 19Ć3 . Overview 19Ć5 Oracle Procedure Builder Capabilities 19Ć7 . Procedure Builder Components 19Ć9 The Object Navigator 19Ć15 . The Interpreter 19Ć23 . The Program Unit Editor 19Ć27 . The Stored Program Unit Editor 19Ć31 Debugging a Stored Program Unit 19Ć33 Performing Debug Actions in the Interpreter 19Ć35 Setting a Breakpoint 19Ć37 Examining Local Variables 19Ć43 . Summary 19Ć45 Practice Overview 19Ć47 Practice 19 19Ć49 20. Modularizing Programming with Subprograms 20Ć1 . Objectives 20Ć3 . Overview 20Ć5 ix Creating a Subprogram 20Ć7 . Creating a Procedure 20Ć9 . Comparing Functions and Procedures 20Ć15 Creating a Function 20Ć17 . Invoking Subprograms 20Ć21 Summary 20Ć29 Practice Overview 20Ć31 Practice 20 20Ć33 21. Developing a Simple PL/SQL Block 21Ć1 . Objectives 21Ć3 . Overview 21Ć5 Declaring PL/SQL Variables and Constants 21Ć7 Declaring Scalar Variables 21Ć9 . Declaring Composite Datatypes 21Ć15 PL/SQL Block Syntax Rules 21Ć25 Assigning Values to Variables 21Ć29 Programming Guidelines 21Ć43 Summary 21Ć49 Practice Overview 21Ć51 Practice 21 21Ć53 22. Interacting with Oracle 22Ć1 . Objectives 22Ć3 . Overview 22Ć5 Retrieving Data Using PL/SQL 22Ć7 SELECT Exceptions 22Ć15 . Manipulating Data Using PL/SQL 22Ć19 . SQL Cursor 22Ć23 Controlling Transactions 22Ć27 . Summary 22Ć31 Practice Overview 22Ć33 Practice 22 22Ć35 23. Controlling Flow in PL/SQL Blocks 23Ć1 Objectives 23Ć3 . Overview 23Ć5 The IF Statement 23Ć7 . Building Logical Conditions 23Ć13 Loop Statements 23Ć17 . Summary 23Ć29 Practice Overview 23Ć31 Practice 23 23Ć33 x 24. Processing Queries by Using Explicit Cursors 24Ć1 . Objectives 24Ć3 . Overview 24Ć5 Controlling Explicit Cursors 24Ć7 Explicit Cursor Attributes 24Ć17 Cursors and Records 24Ć21 . Cursors with Parameters 24Ć23 . Cursor FOR Loops 24Ć25 Applying the WHERE CURRENT OF Clause 24Ć27 Summary 24Ć29 Practice Overview 24Ć31 Practice 24 24Ć33 25. Error Handling 25Ć1 Objectives 25Ć3 . Overview 25Ć5 Exception Types 25Ć7 Trapping Exceptions 25Ć9 Trapping Predefined Oracle7 Server Exceptions 25Ć11 Trapping NonĆPredefined Oracle7 Server Exceptions 25Ć15 Trapping UserĆDefined Exceptions 25Ć17 Error Trapping Functions 25Ć19 Propagating Exceptions 25Ć21 . Summary 25Ć23 Practice Overview 25Ć25 Practice 25 25Ć27 26. Summary of PL/SQL 26Ć1 . Summary 26Ć3 Practice Overview 26Ć9 Practice 26 26Ć11 Volume 4 A Practice Solutions AĆ1 . Preface AĆ3 Practice 1 Solutions AĆ4 . Practice 2 Solutions AĆ8 . Practice 3 Solutions AĆ20 . Practice 4 Solutions AĆ29 . Practice 5 Solutions AĆ39 . Practice 6 Solutions AĆ46 . Practice 7 Solutions AĆ55 . Practice 9 Solutions AĆ59 . Practice 10 Solutions AĆ63 xi Practice 11 Solutions AĆ68 Practice 12 Solutions AĆ82 Practice 13 Solutions AĆ88 Practice 14 Solutions AĆ97 Practice 15 Solutions AĆ105 Practice 16 Solutions AĆ109 Practice 17 Solutions AĆ116 Practice 19 Solutions AĆ154 Practice 20 Solutions AĆ155 Practice 21 Solutions AĆ158 Practice 22 Solutions AĆ163 Practice 23 Solutions AĆ170 Practice 24 Solutions AĆ177 Practice 25 Solutions AĆ186 Practice 26 Solutions AĆ192 B Table Descriptions and Data BĆ1 Summit Sporting Goods Database Diagram BĆ3 S_CUSTOMER Table BĆ4 S_DEPT Table BĆ7 S_EMP Table BĆ8 . S_IMAGE Table BĆ10 . S_INVENTORY Table BĆ11 S_ITEM Table BĆ16 S_ORDTable BĆ20 . S_PRODUCT Table BĆ22 . S_REGION Table BĆ25 . S_WAREHOUSE Table BĆ26 C Using SQL*Plus to Create Reports and Manage PL/SQL Code CĆ1 Objectives CĆ3 . Overview CĆ5 Entering Commands in SQL*Plus CĆ7 . Comparison of SQL and SQL*Plus Commands CĆ9 SQL*Plus SET Commands CĆ11 Creating a Report CĆ15 . Declaring and Creating PL/SQL Blocks CĆ23 Entering Commands in SQL*Plus CĆ25 . Passing Input and Output Values CĆ27 . Debugging in SQL*Plus CĆ31 . Displaying Contents of a Subprogram CĆ35 . Executing Stored Subprograms CĆ37 Summary CĆ41 Practice Overview CĆ43 xii Practice C CĆ45 . Practice C Solutions CĆ47 D Related Products and Services DĆ1 . Related Products DĆ3 . Related Services DĆ5 . Glossary Index . iii Contents Volume 1 Preface xi . in SQL*Plus CĆ31 . Displaying Contents of a Subprogram CĆ35 . Executing