Oracle PLSQL Language- P6
Số trang: 50
Loại file: pdf
Dung lượng: 190.85 KB
Lượt xem: 9
Lượt tải: 0
Xem trước 5 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
Tham khảo tài liệu oracle plsql language- p6, công nghệ thông tin, cơ sở dữ liệu phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả
Nội dung trích xuất từ tài liệu:
Oracle PLSQL Language- 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. ...
Nội dung trích xuất từ tài liệu:
Oracle PLSQL Language- 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. ...
Tìm kiếm theo từ khóa liên quan:
thủ thuật máy tính công nghệ thông tin tin học quản trị mạng computer networkGợi ý tài liệu liên quan:
-
52 trang 430 1 0
-
24 trang 354 1 0
-
Top 10 mẹo 'đơn giản nhưng hữu ích' trong nhiếp ảnh
11 trang 314 0 0 -
Làm việc với Read Only Domain Controllers
20 trang 302 0 0 -
74 trang 296 0 0
-
96 trang 293 0 0
-
Báo cáo thực tập thực tế: Nghiên cứu và xây dựng website bằng Wordpress
24 trang 289 0 0 -
Đồ án tốt nghiệp: Xây dựng ứng dụng di động android quản lý khách hàng cắt tóc
81 trang 281 0 0 -
EBay - Internet và câu chuyện thần kỳ: Phần 1
143 trang 275 0 0 -
Tài liệu dạy học môn Tin học trong chương trình đào tạo trình độ cao đẳng
348 trang 269 1 0