1

I have this SQL query which is used to delete users.

DELETE FROM USERS WHERE USERNAME = ?

The problem is that I don't know is there any row success row removal or not. I always get success at the end.

Is there any way to get for example some confirmation from Oracle that row is deleted in my Java code?

Peter Penzov
  • 1,126
  • 134
  • 430
  • 808

2 Answers2

3

executeUpdate() method of PreparedStatement gives You the number of rows deleted.If no rows have been deleted by the query You get 0.I think that's the easiest solution.

If You need to know which rows have been deleted You can user "Returning" clause, that will give You rows deleted.

Regards

Mikajlo8
  • 81
  • 3
0

You can use SQL%ROWCOUNT. It is an implicit cursor that gives the number of rows affected by SQL statement

declare
begin
DELETE FROM USERS WHERE USERNAME = ?;
dbms_output.put_line('Total Deleted:' ||sql%rowcount);
end;

This will give you the count of the number of rows deleted.

Shankar
  • 879
  • 8
  • 15