Download presentation
Presentation is loading. Please wait.
Published byAndrea Fisher Modified over 9 years ago
1
© 2007 by Prentice Hall7-1 Introduction to Oracle 10g Chapter 7 Using PL/SQL to Your Advantage James Perry and Gerald Post
2
© 2007 by Prentice Hall7-2 Chapter Outline Introducing PL/SQL Understanding Anonymous Blocks Creating Anonymous Blocks Understanding Explicit Cursors Introducing Named Blocks Creating, Using, Listing, and Dropping Functions Creating Procedures
3
© 2007 by Prentice Hall7-3 Table 7.1 Oracle Error CodeMeaning ORA-0001Unique constraint violated. ORA-1001Illegal cursor operation. ORA-1403No data found. ORA-1422A SELECT INTO statement returns more than one row. ORA-1476Division by zero has occurred. ORA-1722Conversion to a number failed; (Attempt to convert a character string, for instance.) ORA-6502Truncation, conversion error, or arithmetic error. ORA-6511Attempt to open a cursor that is already open.
4
© 2007 by Prentice Hall7-4 Table 7.2 Exception name to testMeaning ACCESS_INTO_NULLAttempted to assign a value to an attribute of an uninitialized object. CASE_NOT_FOUNDNone of the WHEN clauses of a CASE structure was selected and there was no ELSE default clause. CURSOR_ALREADY_OPENProgram tried to open a cursor that is already open. INVALID_CURSORProgram tried to perform an illegal cursor activity such as closing an open cursor. NO_DATA_FOUNDA SELECT INTO statement returns zero rows. ROWTYPE_MISMATCHA cursor variable and a PL/SQL variable have incompatible data types. TOO_MANY_ROWSA SELECT INTO statement returned more than one row. VALUE_ERRORA conversion, arithmetic, truncation, or size-constraint error occurred. (For example, an attempt to select a long character column into a shorter PL/SQL variable causes this exception.) ZERO_DIVIDEAttempted to divide a number by zero.
5
© 2007 by Prentice Hall7-5 Table 7.3 Base Salary to Dependent RatioBase Salary Increase $0 – $1,00010% $1,001 – $1,5008% $1,501 – $2,0006% $2,001 – $3,0003% Above $3,000No increase
6
© 2007 by Prentice Hall7-6 7.1 PL/SQL processing
7
© 2007 by Prentice Hall7-7 7.2 Example PL/SQL block
8
© 2007 by Prentice Hall7-8 7.3 Initializing the Redwood Realty database
9
© 2007 by Prentice Hall7-9 7.4 An anonymous PL/SQL block
10
© 2007 by Prentice Hall7-10 7.5 Executing an anonymous PL/SQL block
11
© 2007 by Prentice Hall7-11 error message displayed by the exception-handling code SQLERRM is the text of the error message 7.6 A run-time error using an implicit cursor
12
© 2007 by Prentice Hall7-12 two hyphens turn the SELECT statement into a comment 7.7 Exploring exception handling
13
© 2007 by Prentice Hall7-13 7.8 A completed PL/SQL block containing an explicit cursor
14
© 2007 by Prentice Hall7-14 7.9 Testing an anonymous PL/SQL block containing an explicit cursor
15
© 2007 by Prentice Hall7-15 cursor definition cursor FOR loop 7.10 Using a cursor FOR loop with an explicit cursor
16
© 2007 by Prentice Hall7-16 TrueFalseCondition ? enter exit 7.11 IF statement logic
17
© 2007 by Prentice Hall7-17 SalaryRatio <= 1000 SalaryRatio <= 1500 SalaryRatio <= 2000 SalaryRatio <= 3000 Increment by 10% Increment by 8% Increment by 6% Increment by 3% (no increment) Enter True False Exit 7.12 Business rules logic diagram
18
© 2007 by Prentice Hall7-18 7.13 Implementing a DML statement in a PL/SQL code block
19
© 2007 by Prentice Hall7-19 7.14 Messages indicate the salary increment for each agent
20
© 2007 by Prentice Hall7-20 7.15 Displaying compile-time error information.
21
© 2007 by Prentice Hall7-21 7.16 Calling a user-defined function
22
© 2007 by Prentice Hall7-22 7.17 Error messages indicating an invalid AgentID value
23
© 2007 by Prentice Hall7-23 new code line new code lines new code line 7.18 Modified Age function
24
© 2007 by Prentice Hall7-24 modified Age function testing the Age function with good and bad data values 7.19 Testing the modified Age function
25
© 2007 by Prentice Hall7-25 User_Source description Age function source code stored in the database 7.20 Displaying User_Source’s structure and information about a stored function
26
© 2007 by Prentice Hall7-26 7.21 Completed ForSale source code (shown in Notepad)
27
© 2007 by Prentice Hall7-27 7.22 Message indicating the procedure is syntax-error free
28
© 2007 by Prentice Hall7-28 call to ForSale without an argument and resulting error messages 7.23 Testing the ForSale procedure
29
© 2007 by Prentice Hall7-29 new line three new lines 7.24 Testing the newly modified ForSale procedure
30
© 2007 by Prentice Hall7-30 7.25 Displaying a procedure’s source code
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.