Search code examples
sqldb2warnings

How to not get this warning? DB2 Warning SQLSTATE=02000 No row was found for FETCH, UPDATE, or DELETE; or the result of a query is an empty table


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.


Solution

  • 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