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 > DB2 > NO DATA FOUND IN db2

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-22-09, 05:38
donraja_ht donraja_ht is offline
Registered User
 
Join Date: Sep 2007
Posts: 56
NO DATA FOUND IN db2

Hello,

As there is NO_DATA_FOUND exception in oracle similarly what and how can we handle a NO_DATA_FOUND exception in a DB2 Procedure eg.

start procedure
select field_name from table_name where <condition>
end procedure

if there are no fields in this table "table_name" i.e if there are no records in this table which meets the given condition then I would like to handle NO_DATA_FOUND exception in DB2, can anybody give me some idea as to how this is handled in DB2 procedures, also plz provide me a piece of code that does this.

thanks

Last edited by donraja_ht; 04-22-09 at 05:41.
Reply With Quote
  #2 (permalink)  
Old 04-22-09, 05:42
dr_te_z dr_te_z is offline
Registered User
 
Join Date: Jan 2009
Location: Zoetermeer, Holland
Posts: 555
as far as i know DB2 does not support this feature.... yet.
Just wait 5 more weeks. The next version of db2 (V9.7) DOES understand the PL-SQL syntax.

In the mean time: a way to avoid this is to use the MERGE verb intead of UPDATE with an INSERT in the not-found-block.
Reply With Quote
  #3 (permalink)  
Old 04-22-09, 06:38
rahul_s80 rahul_s80 is offline
Registered User
 
Join Date: Jul 2006
Location: Pune , India
Posts: 433
Quote:
Originally Posted by dr_te_z
as far as i know DB2 does not support this feature.... yet.
Just wait 5 more weeks. The next version of db2 (V9.7) DOES understand the PL-SQL syntax.
? why

DECLARE V_ROW_COUNT INTEGER DEFAULT 0;

-- Declare Exception Handlers

DECLARE NOT_FOUND CONDITION FOR SQLSTATE '02000';
DECLARE CONTINUE HANDLER FOR NOT_FOUND SET V_ROW_COUNT = 1 ;
__________________
Rahul Singh
Certified DB2 9 DBA / Application Developer
Reply With Quote
  #4 (permalink)  
Old 04-23-09, 07:10
dr_te_z dr_te_z is offline
Registered User
 
Join Date: Jan 2009
Location: Zoetermeer, Holland
Posts: 555
Fascinating!
Still: I used to be a cobol programmer using embedded SQL. Also in cobol you can test the SQLCODE act accordonly. However, SQLCODES 0 and 100 are ANSI standards (and an update throws another non-ansi code if a row is not found) so I always propagated to check first (select count(*)) and based upon the ANSI-value of SQLCODE do an update or an insert. The same can be coded in (PL)SQL(PL) and clean and portable code as a result.

But, like I posted before: this is all history because we have the MERGE verb now
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