Home > Software engineering >  How to not get this warning? DB2 Warning SQLSTATE=02000 No row was found for FETCH, UPDATE, or DELET
How to not get this warning? DB2 Warning SQLSTATE=02000 No row was found for FETCH, UPDATE, or DELET

Time:05-04

The way we have our error handling setup this warning will shoot an email out to everyone when it occurs (I can't change this). I really don't care that no rows were found for this job.

How do I either

A) Check if a row is present before tying to delete it or

B) Circumvent/ignore this warning somehow?

Example of the delete:

 delete from schema.table 
   where key is null;

SQLSTATE=02000 No row error was displayed for FETCH, UPDATE, or DELETE; or the result of a query is an empty table.

I cannot insert a dummy record to delete either.

CodePudding user response:

Maybe this will do

with delete_rows as (
  select * from old table (delete from schema.table where key is null)
)
select count(*) from delete_rows

CodePudding user response:

You may try Compound SQL (compiled) statement "eating" this warning.

BEGIN
  DECLARE CONTINUE HANDLER FOR NOT FOUND
  BEGIN END;
  DELETE ...;
END
  • Related