473,614 Members | 2,321 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Bulk-Fetching from a Cursor

debasisdas
8,127 Recognized Expert Expert
We can fetch from a cursor into one or more collections:

Expand|Select|Wrap|Line Numbers
  1. DECLARE
  2. TYPE NameList IS TABLE OF employees.last_name%TYPE;
  3. TYPE SalList IS TABLE OF employees.salary%TYPE;
  4. CURSOR c1 IS SELECT last_name, salary FROM employees WHERE salary > 10000;
  5. names NameList;
  6. sals SalList;
  7. TYPE RecList IS TABLE OF c1%ROWTYPE;
  8. recs RecList;
  9. PROCEDURE print_results IS
  10. BEGIN
  11. dbms_output.put_line('Results:');
  12. IF names IS NULL OR names.COUNT = 0 THEN
  13. RETURN; -- Don't print anything if collections are empty.
  14. END IF;
  15. FOR i IN names.FIRST .. names.LAST
  16. LOOP
  17. dbms_output.put_line(' Employee ' || names(i) || ': $' ||
  18. sals(i));
  19. END LOOP;
  20. END;
  21. BEGIN
  22. dbms_output.put_line('--- Processing all results at once ---');
  23. OPEN c1;
  24. FETCH c1 BULK COLLECT INTO names, sals;
  25. CLOSE c1;
  26. print_results;
  27. dbms_output.put_line('--- Processing 7 rows at a time ---');
  28. OPEN c1;
  29. LOOP
  30. --LIMIT restricts the number of records to fetch.
  31. FETCH c1 BULK COLLECT INTO names, sals LIMIT 7;
  32. EXIT WHEN c1%NOTFOUND;
  33. print_results;
  34. END LOOP;
  35. -- Loop exits when fewer than 7 rows are fetched. Have to
  36. -- process the last few. Need extra checking inside PRINT_RESULTS
  37. -- in case it is called when the collection is empty.
  38. print_results;
  39. CLOSE c1;
  40. dbms_output.put_line('--- Fetching records rather than columns ---');
  41. OPEN c1;
  42. FETCH c1 BULK COLLECT INTO recs;
  43. FOR i IN recs.FIRST .. recs.LAST
  44. LOOP
  45. -- Now all the columns from the result set come from a single record.
  46. dbms_output.put_line(' Employee ' || recs(i).last_name || ': $'
  47. || recs(i).salary);
  48. END LOOP;
  49. END;
Jan 2 '08 #1
0 5517

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2997
by: jason | last post by:
What are the technical challenges in getting a local SMTP email server set up on a win3k system or alternatively on a win2k pro local work statation. We are on the verge of acquiring a new win3k system for local asp testing development purposes and to allow satellite branches to ftp-in and grab images. I need to utilize the bulk emailing facility to send up to 20,000 emails a day after looping through my customer list which resides in...
1
10632
by: Paul Rowe | last post by:
Hi "You" I have two collection types declared at the SQL level. 1. Do you know of any known bugs with the BULK COLLECT clause used with the TABLE operator? I have a situation now where I am using a BULK COLLECT clause with a SELECT statement and a TABLE() operator in a join. I am finding that this select statement either returns the wrong result or the right result. The wrong result is always the same... too many rows where the...
2
4961
by: Chris | last post by:
Any help would be appreciated. I am running a script that does the following in succession. 1-Drop existing database and create new database 2-Defines tables, stored procedures and functions in the database 3-Imports data using bulk insert 4-Analyzes data using stored procedures I would like to improve the performance of the analysis in step 4 by
2
16498
by: php newbie | last post by:
Hello, I am trying to load a simple tab-delimited data file to SQL Server. I created a format file to go with it, since the data file differs from the destination table in number of columns. When I execute the query, I get an error saying that only sysadmin or bulkadmin roles are allowed to use the BULK INSERT statement. So, I proceeded with the Enterprise Manager to grant myself those roles. However, I could not find sysadmin or...
5
4891
by: me | last post by:
I'm also having problems getting the bulk insert to work. I don't know anything about it except what I've gleened from BOL but I'm not seeming to get anywhere...Hopefully there is some little (or big) problem with my code that someone can point out that may save me some time. TIA CBL
7
12113
by: iqbal | last post by:
Hi all, We have an application through which we are bulk inserting rows into a view. The definition of the view is such that it selects columns from a table on a remote server. I have added the servers using sp_addlinkedserver on both database servers. When I call the Commit API of oledb I get the following error: Error state: 1, Severity: 19, Server: TST-PROC22, Line#: 1, msg:
6
12347
by: pk | last post by:
Sorry for the piece-by-piece nature of this post, I moved it from a dormant group to this one and it was 3 separate posts in the other group. Anyway... I'm trying to bulk insert a text file of 10 columns into a table with 12. How can I specify which columns to insert to? I think format files are what I'm supposed to use, but I can't figure them out. I've also tried using a view, as was suggested on one of the many websites I've...
3
33228
by: moonriver | last post by:
Right now I develop an application to retrieve over 30,000 records from a binary file and then load them into a SQL Server DB. So far I load those records one by one, but the performance is very poor: it takes more than 6 hours to finish the loading. So could I make use of the bulk-insert mechanism of SQL Server to reduce the loading time in C# codes? or other performance improvement solutions?
11
28326
by: Ted | last post by:
OK, I tried this: USE Alert_db; BULK INSERT funds FROM 'C:\\data\\myData.dat' WITH (FIELDTERMINATOR='\t', KEEPNULLS, ROWTERMINATOR='\r\n');
0
3004
by: ozkhillscovington | last post by:
We have sp's in place that do BULK INSERTS from txt files into the tables. This works fine, however they have asked us to add a field that identifies accounting ctr. The only thing that identifies accounting ctr is the last three letters of the text file being used for the BULK INSERT. How would you suggest that I do this? Is there a way to add a default value to the .fmt or schema files for the text fields, or in the BULK INSERT...
0
8197
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8142
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8640
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8287
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8443
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7114
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6093
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
2573
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1757
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.