Danh mục

Oracle PL/SQL Language Pocket Reference- P6

Số trang: 50      Loại file: pdf      Dung lượng: 190.85 KB      Lượt xem: 16      Lượt tải: 0    
10.10.2023

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- P6: 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- P6 SQL and dont expect any of the cursor attributes to be available for your cursor variables. NOTE: The client-server aspect of this sharing will only really come into play when the Oracle Developer/2000 tools are converted to use PL/SQL Release 2.3 or above. This process, shown in Figure 6.2, offers dramatic new possibilities for data sharing and cursor management in PL/SQL programs. Figure 6.2: Referencing a cursor variable across two programs The code you write to take advantage of cursor variables is very similar to that for explicit cursors. The following example declares a cursor type (called a REF CURSOR type) for the company table, then opens, fetches from, and closes the cursor: DECLARE /* Create the cursor type. */ TYPE company_curtype IS REF CURSOR RETURN company% ROWTYPE; /* Declare a cursor variable of that type. */ company_curvar company_curtype; /* Declare a record with same structure as cursor variable. */ company_rec company%ROWTYPE; BEGINPlease purchase PDF Split-Merge on www.verypdf.com to remove this watermark. /* Open the cursor variable, associating with it a SQL statement. */ OPEN company_curvar FOR SELECT * FROM company; /* Fetch from the cursor variable. */ FETCH company_curvar INTO company_rec; /* Close the cursor object associated with variable. */ CLOSE company_curvar; END; That looks an awful lot like explicit cursor operations, except for the following: q The REF CURSOR type declaration q The OPEN FOR syntax which specified the query at the time of the open While the syntax is very similar, the fact that the cursor variable is a variable opens up many new opportunities in your programs. These are explored in the remainder of this section. 6.12.1 Features of Cursor Variables Cursor variables let you: q Associate a cursor variable with different queries at different times in your program execution. In other words, a single cursor variable can be used to fetch from different result sets. q Pass a cursor variable as an argument to a procedure or function. You can, in essence, share the results of a cursor by passing the reference to that result set. q Employ the full functionality of static PL/SQL cursors for cursor variables. You can OPEN, CLOSE, and FETCH with cursor variables within your PL/SQL programs. You can reference the standard cursor attributes -- %ISOPEN, %FOUND, %NOTFOUND, and % ROWCOUNT -- for cursor variables. q Assign the contents of one cursor (and its result set) to another cursor variable. Because the cursor variable is a variable, it can be used in assignment operations. There are, however, restrictions on referencing this kind of variable, addressed later in this chapter. 6.12.2 Similarities to Static Cursors One of the key design requirements for cursor variables was that as much as possible the semantics used to manage cursor objects would be the same as that of static cursors. While the declaration of a cursor variable and the syntax for opening it are enhanced, the following cursor operations are unchanged for cursor variables: q The CLOSE statement. In the following example I declare a REF CURSOR type and a cursor variable based on that type. Then I close the cursor variable using the same syntax as for that of a static cursor:Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. DECLARE TYPE var_cur_type IS REF CURSOR; var_cur var_cur_type; BEGIN CLOSE var_cur; END; q Cursor attributes. You can use any of the four cursor attributes with exactly the same syntax as for that of a static cursor. The rules governing the use and values returned by those attributes match that of explicit cursors. If I have declared a variable cursor as in the previous example, I could use all the cursor attributes as follows: var_cur%ISOOPEN var_cur%FOUND var_cur%NOTFOUND var_cur%ROWCOUNT q Fetching from the cursor variable. You use the same FETCH syntax when fetching from a cursor variable into local PL/SQL data structures. There are, however, additional rules applied by PL/SQL to make sure that the data structures of the cursor variables row (the set of values returned by the cursor object) match that of the data structures to the right of the INTO keyword. These rules are discussed in Section 6.12.6, Rules for Cursor Variables. Because the syntax for these aspects of cursor variables remain unchanged, I wont cover them again in the remainder of this section. Instead I will focus on the new capabilities available and the changed syntax required for cursor variables. 6.12.3 Declaring REF CURSOR Types and Cursor Variables Just as with a PL/SQL table or a programmer-defined record, you must perform two distinct declaration steps in order to create a cursor variable: 1. Create a referenced cursor TYPE. 2. Declare the actual cursor variable based on that type. The syntax for creating a referenced cursor type is as follows: TYPE cursor_type_name IS REF CURSOR [ RETURN return_type ]; where cursor_type_name is the name of the type of cursor and return_type is the RETURN data specification for the cursor type. The return_type can be any of the data structures valid for a normal cursor RETURN clause, defined using the %ROWTYPE attribute or by referencing a ...

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