473,406 Members | 2,281 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

EXCEPTION block called erroneously - help

I am running a PL/SQL module in which I do the following....

BEGIN
DBMS_OUTPUT.enable(1000000);

-- Open file for writing.
OutfileHandler1 := UTL_FILE.FOPEN(wc_file_path, wc_output_file1,
'W'); -- output report
-- Get the CUSTOMER records by reading the CUSTOMER table.

ws_error_loc := 1005;
OPEN cust_cur;
-- Get a customer record that is among the qualifying types.
LOOP -- cust_cur looping
ws_error_loc := 1010;
FETCH cust_cur INTO cust_rec;
EXIT WHEN cust_cur%NOTFOUND;
ws_ct_cust:=ws_ct_cust+1;
....
Do a bunch of processing (i.e.: creating a report)
....

END LOOP;
CLOSE cust_cur;

UTL_FILE.FCLOSE(OutfileHandler1);

EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('***** TAX EXEMPTION INFORMATION
*****');
DBMS_OUTPUT.PUT_LINE('ERROR : ' || TO_CHAR(SQLCODE) || ' -
');
DBMS_OUTPUT.PUT_LINE(SQLERRM);
DBMS_OUTPUT.PUT_LINE(' at location : ' || ws_error_loc );
DBMS_OUTPUT.PUT_LINE(' CUST-NO............' ||
cust_rec.ky_cust_no);
DBMS_OUTPUT.PUT_LINE(' KY-BA..............' ||
ba_rec.ky_ba);
DBMS_OUTPUT.PUT_LINE(' CD_BUS.............' || te_rec.cd_bus
);
DBMS_OUTPUT.PUT_LINE(' KY-PROD-ORDNO......' ||
te_rec.ky_prod_ordno );
DBMS_OUTPUT.PUT_LINE(' CD-TAX-TYPE........' ||
te_rec.cd_tax_type );
DBMS_OUTPUT.PUT_LINE(' PC-TAX-EXCEP.......' ||
te_rec.pc_tax_excep );
ROLLBACK;

END;
/
exit;

The "cust_cur" looks like this, from my DECLARATION section...

-- CUSTOMER table dursor
CURSOR cust_cur
IS
SELECT ky_cust_no,
nm_cust_1,
cd_cust_type,
cd_co,
nm_cust_2
FROM customer
WHERE cd_cust_type NOT IN
('1' , -- VS-NATIONAL
'F' , -- VS-GOVT-FEDERAL
'I' , -- VS-INDIVIDUAL
'M' , -- VS-GOVT-MUNICIPAL
'S' , -- VS-GOVT-ST
'T' , -- VS-GOVT-AUTH
'Y' , -- VS-GOVT-COUNTY
'E' ) -- VS-COMPANY-USE
ORDER BY ky_cust_no;
cust_rec cust_cur%ROWTYPE;
(Note tht I had some diagnostic PUT_LINE statements that I'd edited
out, for clarity). After the last qualifying "cust_rec" is processed,
upon the next "FETCH" when the "EXIT" should execute, this does NOT
appear to be happening, rather, control is passed to the EXCEPTION
block. The SQLERRM that is written is "User-Defined Exception", while
the SQLCODE is "1" (which only occurs upon update or insert - "Unique
constraint violation" - so this is not even valid in this situation,
since I'm just "SELECT"ing).

I have no idea why the loop is not exited!!!
There is only one CUSTOMER record with this particular ky_cust_no.
I even went so far in my testing as to determine the maximum
ky_cust_no, then before performing the FETCH, attempting to EXIT WHEN
this value is the same as that which is already contained in
"cust_rec.ky_cust_no" (from the prior FETCH), - I STILL get the
execution of the EXCEPTION block.

When I comment out the EXCEPTION block, I get ...
*
ERROR at line 1:
ORA-06510: PL/SQL: unhandled user-defined exception
ORA-06512: at "SYS.UTL_FILE", line 103
ORA-06512: at "SYS.UTL_FILE", line 120
ORA-06512: at "SYS.UTL_FILE", line 218
ORA-06512: at line 471
in which, these line numbers make absolutely no sense.
Any suggestion would be greatly appreciated - I'm gettin'
frustrated!!!
Jul 19 '05 #1
1 3633
Scott J. Chlebove wrote:
I am running a PL/SQL module in which I do the following....

BEGIN
DBMS_OUTPUT.enable(1000000);

-- Open file for writing.
OutfileHandler1 := UTL_FILE.FOPEN(wc_file_path, wc_output_file1,
'W'); -- output report
-- Get the CUSTOMER records by reading the CUSTOMER table.

ws_error_loc := 1005;
OPEN cust_cur;
-- Get a customer record that is among the qualifying types.
LOOP -- cust_cur looping
ws_error_loc := 1010;
FETCH cust_cur INTO cust_rec;
EXIT WHEN cust_cur%NOTFOUND;
ws_ct_cust:=ws_ct_cust+1;
...
Do a bunch of processing (i.e.: creating a report)
...

END LOOP;
CLOSE cust_cur;

UTL_FILE.FCLOSE(OutfileHandler1);

EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('***** TAX EXEMPTION INFORMATION
*****');
DBMS_OUTPUT.PUT_LINE('ERROR : ' || TO_CHAR(SQLCODE) || ' -
');
DBMS_OUTPUT.PUT_LINE(SQLERRM);
DBMS_OUTPUT.PUT_LINE(' at location : ' || ws_error_loc );
DBMS_OUTPUT.PUT_LINE(' CUST-NO............' ||
cust_rec.ky_cust_no);
DBMS_OUTPUT.PUT_LINE(' KY-BA..............' ||
ba_rec.ky_ba);
DBMS_OUTPUT.PUT_LINE(' CD_BUS.............' || te_rec.cd_bus
);
DBMS_OUTPUT.PUT_LINE(' KY-PROD-ORDNO......' ||
te_rec.ky_prod_ordno );
DBMS_OUTPUT.PUT_LINE(' CD-TAX-TYPE........' ||
te_rec.cd_tax_type );
DBMS_OUTPUT.PUT_LINE(' PC-TAX-EXCEP.......' ||
te_rec.pc_tax_excep );
ROLLBACK;

END;
/
exit;

The "cust_cur" looks like this, from my DECLARATION section...

-- CUSTOMER table dursor
CURSOR cust_cur
IS
SELECT ky_cust_no,
nm_cust_1,
cd_cust_type,
cd_co,
nm_cust_2
FROM customer
WHERE cd_cust_type NOT IN
('1' , -- VS-NATIONAL
'F' , -- VS-GOVT-FEDERAL
'I' , -- VS-INDIVIDUAL
'M' , -- VS-GOVT-MUNICIPAL
'S' , -- VS-GOVT-ST
'T' , -- VS-GOVT-AUTH
'Y' , -- VS-GOVT-COUNTY
'E' ) -- VS-COMPANY-USE
ORDER BY ky_cust_no;
cust_rec cust_cur%ROWTYPE;
(Note tht I had some diagnostic PUT_LINE statements that I'd edited
out, for clarity). After the last qualifying "cust_rec" is processed,
upon the next "FETCH" when the "EXIT" should execute, this does NOT
appear to be happening, rather, control is passed to the EXCEPTION
block. The SQLERRM that is written is "User-Defined Exception", while
the SQLCODE is "1" (which only occurs upon update or insert - "Unique
constraint violation" - so this is not even valid in this situation,
since I'm just "SELECT"ing).

I have no idea why the loop is not exited!!!
There is only one CUSTOMER record with this particular ky_cust_no.
I even went so far in my testing as to determine the maximum
ky_cust_no, then before performing the FETCH, attempting to EXIT WHEN
this value is the same as that which is already contained in
"cust_rec.ky_cust_no" (from the prior FETCH), - I STILL get the
execution of the EXCEPTION block.

When I comment out the EXCEPTION block, I get ...
*
ERROR at line 1:
ORA-06510: PL/SQL: unhandled user-defined exception
ORA-06512: at "SYS.UTL_FILE", line 103
ORA-06512: at "SYS.UTL_FILE", line 120
ORA-06512: at "SYS.UTL_FILE", line 218
ORA-06512: at line 471
in which, these line numbers make absolutely no sense.
Any suggestion would be greatly appreciated - I'm gettin'
frustrated!!!


The "usual" way of processing is:
- open cursor
- fetch
- loop (or: while %FOUND)
- exit when %NOTFOUND (not if while %FOUND is used)
- fetch
- end loop.

#2 is missing (as well as info re Oracle version...)
what about:

for x in ( SELECT ky_cust_no,
nm_cust_1,
cd_cust_type,
cd_co,
nm_cust_2
FROM customer
WHERE cd_cust_type NOT IN
('1' , -- VS-NATIONAL
'F' , -- VS-GOVT-FEDERAL
'I' , -- VS-INDIVIDUAL
'M' , -- VS-GOVT-MUNICIPAL
'S' , -- VS-GOVT-ST
'T' , -- VS-GOVT-AUTH
'Y' , -- VS-GOVT-COUNTY
'E' ) -- VS-COMPANY-USE
ORDER BY ky_cust_no) loop
dbms_output.put_line('Cust_no '||to_char(x.ky_cust_no));
end loop;
etc.

Re the exception, and line#: those lines refer to UTL_FILE, not your
proc. The error occurs in line 471 of your proc (which must be doing
something with the file, as UTL_FILE is called)
--
Merry Christmas and a Happy New Year,
Frank van Bortel

Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

40
by: Kevin Yu | last post by:
is it a bad programming design to throw exception in the try block then catch it??
14
by: Chad Z. Hower aka Kudzu | last post by:
Its a bit tough to explain why I need this, so I wont. Consider it academic for now. I would like to detect if an exception is currently being thrown, but I cannot use a try statement. This is...
3
by: will | last post by:
Hi all. I've got an question about how to catch an exception. In Page_Load, I place a DataGrid, dg1, into edit mode. This will call the method called GenericGridEvent. GenericGridEvent will call...
10
by: junw2000 | last post by:
Hi, Below is a simple code about exception. #include <iostream> using namespace std; struct E { const char* message; E(const char* arg) : message(arg) { } };
132
by: Zorro | last post by:
The simplicity of stack unraveling of C++ is not without defective consequences. The following article points to C++ examples showing the defects. An engineer aware of defects can avoid...
6
by: Fir5tSight | last post by:
Hi, What does "throw" do? I understand that it throws an error when certain exceptional situation happens. My guess is that this *ignores* the error and *continues* so that it prevents the...
14
by: Rex | last post by:
Re: Looking for Tips/Writeup on overall approach to Exception Processing Hi All - I am fairly new to C# and am wondering how to best implement (overall) Exception Processing within my...
4
by: Sunil Varma | last post by:
Hi, Here is a piece of code where the constructor throws an exception. class A { int n; public: A() try{
2
by: =?Utf-8?B?UG9sbHkgQW5uYQ==?= | last post by:
Hi, I am using the Exception Handling Application Block, which is lovely. I have been able to create a flat file as well as create an entry in the Event Log. However I am unable to create an...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...

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.