Danh mục

Oracle PL/SQL Language Pocket Reference- P7

Số trang: 50      Loại file: pdf      Dung lượng: 159.10 KB      Lượt xem: 14      Lượt tải: 0    
Hoai.2512

Phí tải xuống: 15,000 VND Tải xuống file đầy đủ (50 trang) 0
Xem trước 5 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

Oracle PL/SQL Language Pocket Reference- P7: This pocket guide features quick-reference information to help you use Oracles PL/SQL language. It includes coverage of PL/SQL features in the newest version of Oracle, Oracle8i. It is a companion to Steven Feuerstein and Bill Pribyls bestselling Oracle PL/SQL Programming. Updated for Oracle8, that large volume (nearly 1,000 pages) fills a huge gap in the Oracle market, providing developers with a single, comprehensive guide to building applications with PL/SQL and building them the right way. ...
Nội dung trích xuất từ tài liệu:
Oracle PL/SQL Language Pocket Reference- P7 as a whole. 6.3.2.2 Vulnerability to data errors If an implicit SELECT statement returns more than one row, it raises the TOO_MANY_ROWS exception. When this happens, execution in the current block terminates and control is passed to the exception section. Unless you deliberately plan to handle this scenario, use of the implicit cursor is a declaration of faith. You are saying, I trust that query to always return a single row! It may well be that today, with the current data, the query will only return a single row. If the nature of the data ever changes, however, you may find that the SELECT statement which formerly identified a single row now returns several. Your program will raise an exception. Perhaps this is what you will want. On the other hand, perhaps the presence of additional records is inconsequential and should be ignored. With the implicit query, you cannot easily handle these different possibilities. With an explicit query, your program will be protected against changes in data and will continue to fetch rows without raising exceptions. 6.3.2.3 Diminished programmatic control The implicit cursor version of a SELECT statement is a black box. You pass the SQL statement to the SQL layer in the database and it returns (you hope) a single row. You cant get inside the separate operations of the cursor, such as the open and close stages. You cant examine the attributes of the cursor -- to see whether a row was found, for example, or if the cursor has already been opened. You cant easily apply traditional programming control constructs, such as an IF statement, to your data access. Sometimes you dont need this level of control. Sometimes you just think you dont need this level of control. I have found that if I am going to build programs in PL/SQL, I want as much control as I can possibly get. Always Use Explicit Cursors! My rule of thumb is always to use an explicit cursor for all SELECT statements in my applications, even if an implicit cursor might run a little bit faster and even if, by coding an explicit cursor, I have to write more code (declaration, open, fetch, close). By setting and following this clear-cut rule, I give myself one less thing to think about. I do not have to determine if a particular SELECT statement will return only one row and therefore be a candidate for an implicit cursor. I do not have to wonder about the conditions under which a single-row query might suddenly return more than one row, thus requiring a TOO_MANY_ROWS exception handler. I am guaranteed to get vastly improved programmatic control over that data access and more finely- tuned exception handling for the cursor.Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 6.3.3 Explicit Cursors An explicit cursor is a SELECT statement that is explicitly defined in the declaration section of your code and, in the process, assigned a name. There is no such thing as an explicit cursor for UPDATE, DELETE, and INSERT statements. With explicit cursors, you have complete control over how to access information in the database. You decide when to OPEN the cursor, when to FETCH records from the cursor (and therefore from the table or tables in the SELECT statement of the cursor) how many records to fetch, and when to CLOSE the cursor. Information about the current state of your cursor is available through examination of the cursor attributes. This granularity of control makes the explicit cursor an invaluable tool for your development effort. Lets look at an example. The following anonymous block looks up the employee type description for an employee type code: 1 DECLARE 2 /* Explicit declaration of a cursor */ 3 CURSOR emptyp_cur IS 4 SELECT emptyp.type_desc 5 FROM employees emp, employee_type emptyp 6 WHERE emp.type_code = emptyp.type_code; 7 BEGIN 8 /* Check to see if cursor is already open. If not, open it. */ 9 IF NOT emptyp_cur%ISOPEN 10 THEN 11 OPEN emptyp_cur; 12 END IF; 13 14 /* Fetch row from cursor directly into an Oracle Forms item */ 15 FETCH emptyp_cur INTO :emp.type_desc; 16 17 /* Close the cursor */ 18 CLOSE emptyp_cur; 19 END; This PL/SQL block performs the following cursor actions: Action Line(s)Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Declare the cursor 3 Open the cursor (if not already open) 9, 11 Fetch one or more rows from the cursor 15 Close the cursor 18 The next few sections examine each of these steps in more detail. For the remainder of this chapter, unless noted otherwise, the word cursor refers to the explicit cursor. Previous: 6.2 Cursors in PL/ Oracle PL/SQL Next: 6.4 Declaring Cursors SQL Programming, 2nd Edition 6.2 Cursors in PL/SQL Book Index 6.4 Declaring Cursors The Oracle Library Navigation Copyright (c) 2000 OReilly & Associates. All rights reserved.Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Previous: 6.1 Transaction Chapter 6 Next: 6.3 Implicit and Management Database Interaction and Explicit Cursors Cursors 6.2 Cursors in PL/SQL When you execute a SQL statement from PL/SQL, the Oracle RDBMS assigns a private work area for that statement. This work area contains information about the SQL statement ...

Tài liệu được xem nhiều: