cursor loops
From: Lyall Barbour <lyallbarbour_at_sanfranmail.com>
Date: Wed, 30 May 2012 11:12:05 -0400
Message-ID: <20120530151205.50620_at_gmx.com>
Hello everyone,
My developers at our shop have issues with learning new stuff. When i say "new", i really mean old... Implicit cursors haven't even been discovered by them yet. Anyways, what would be a good way of having a cursor, trying to find out if there's anything in it, doing one specific thing if there is, then loop and doing same thing over and over? Here's current code/way of doing it:
OPEN inv_data;
FETCH inv_data INTO inv_rec;
IF inv_data%FOUND
THEN
v_file :=
sys.utl_file.fopen(location => 'SPEMETALS_OUT_DIR'
,filename => v_inv_import_file
,open_mode => 'w');
sys.utl_file.put_line(v_file, 'wt' || ',' || 'pcs' <snip, just writing a "header" line in the file>
LOOP
EXIT WHEN inv_data%NOTFOUND;
Date: Wed, 30 May 2012 11:12:05 -0400
Message-ID: <20120530151205.50620_at_gmx.com>
Hello everyone,
My developers at our shop have issues with learning new stuff. When i say "new", i really mean old... Implicit cursors haven't even been discovered by them yet. Anyways, what would be a good way of having a cursor, trying to find out if there's anything in it, doing one specific thing if there is, then loop and doing same thing over and over? Here's current code/way of doing it:
OPEN inv_data;
FETCH inv_data INTO inv_rec;
IF inv_data%FOUND
THEN
v_file :=
sys.utl_file.fopen(location => 'SPEMETALS_OUT_DIR'
,filename => v_inv_import_file
,open_mode => 'w');
sys.utl_file.put_line(v_file, 'wt' || ',' || 'pcs' <snip, just writing a "header" line in the file>
|| 'a_item' || ',' || 'a_type');
LOOP
EXIT WHEN inv_data%NOTFOUND;
sys.utl_file.put_line(v_file, inv_rec.wt || ',' || inv_rec.pcs <snip, writing out all the rows from the cursor to the file>
|| inv_rec.a_item || ',' || inv_rec.a_type);
FETCH inv_data INTO inv_rec;
END LOOP;
sys.utl_file.fclose(v_file);
END IF;
CLOSE inv_data;
Can I use an EXCEPTION Clause? Is the above the best way to do it, with Explicit cursors?
TIA,
Lyall Barbour
-- http://www.freelists.org/webpage/oracle-lReceived on Wed May 30 2012 - 10:12:05 CDT