If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Oracle > Exception handling in Oracle 8

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-28-04, 15:49
pvar pvar is offline
Registered User
 
Join Date: Jan 2004
Location: USA
Posts: 13
Exception handling in Oracle 8

Hi,

How do I bypass raising an exception by Oracle when it cannot find data for a SELECT statement? I need to continue processing after the SELECT even though it didn't fetch any rows. It is not going to the SQL%NOTFOUND check block after the SELECT statement, rather, it goes to the exception block and breaking out of the program.

I know that I could have a seperate exception handling block for the SELECT and keep the process continue with the outer block. Since I have multiple SELECT checks to do, is there any other way to accomplish this?

Thanks in advance for suggestions.
Reply With Quote
  #2 (permalink)  
Old 01-28-04, 15:54
anacedent anacedent is offline
Registered User
 
Join Date: Aug 2003
Location: Where the Surf Meets the Turf @Del Mar, CA
Posts: 6,415
EXCEPTION
WHEN OTHERS THEN RETURN;
END;
Reply With Quote
  #3 (permalink)  
Old 01-28-04, 16:01
lynden.zhang lynden.zhang is offline
Registered User
 
Join Date: Jan 2004
Location: North Haven, CT
Posts: 110
Or you can define explicit cursors for the select statement and use
cursor_name%NOTFOUND. No exception will be raised when no data found in this way. Otherwise you have to use multiple begin-exception-end blocks for individual selects.
Reply With Quote
  #4 (permalink)  
Old 01-28-04, 16:02
pvar pvar is offline
Registered User
 
Join Date: Jan 2004
Location: USA
Posts: 13
That will still exit from my procedure. I want to have a single procedure where I need to try multiple SELECT's one after another and I want to continue with the processing even when any of the SELECT returns no rows.

Quote:
Originally posted by anacedent
EXCEPTION
WHEN OTHERS THEN RETURN;
END;
Reply With Quote
  #5 (permalink)  
Old 01-28-04, 16:31
anacedent anacedent is offline
Registered User
 
Join Date: Aug 2003
Location: Where the Surf Meets the Turf @Del Mar, CA
Posts: 6,415
1 declare
2 v_timestamp varchar2(32);
3 begin
4 dbms_output.put_line('Before');
5 begin
6 select timestamp into v_timestamp from sysstats where 1 = 2;
7 EXCEPTION
8 WHEN no_data_found THEN null;
9 end;
10 dbms_output.put_line('After ');
11 begin
12 select timestamp into v_timestamp from sysstats where 1 = 2;
13 EXCEPTION
14 WHEN no_data_found THEN null;
15 end;
16 select to_char(sysdate,'YYYY-MON-DD:HH24:MI') into v_timestamp from dual;
17 dbms_output.put_line('Now is - ' || v_timestamp);
18 EXCEPTION
19 WHEN OTHERS THEN NULL;
20* END;
bcm@MWH.ARES.MWH.COM> /
Before
After
Now is - 2004-JAN-28:13:27

PL/SQL procedure successfully completed.
Reply With Quote
  #6 (permalink)  
Old 01-29-04, 08:18
pvar pvar is offline
Registered User
 
Join Date: Jan 2004
Location: USA
Posts: 13
Thank you guys for your valuable suggestions. I tried both the methods and both are working. But I still wish I could check the SQLCODE for a not found case immedialtely after the SELECT without worrying about the exceptions like what I used to do in Informix 4GL.
Reply With Quote
  #7 (permalink)  
Old 07-16-09, 04:53
jselvalakshmi jselvalakshmi is offline
Registered User
 
Join Date: May 2008
Posts: 3
difference between userdefined exception and raise_applivation_error in oracle
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On