Skip to content
Advertisement

Proper way of checking if row exists in table in PL/SQL block

I was writing some tasks yesterday and it struck me that I don’t really know THE PROPER and ACCEPTED way of checking if row exists in table when I’m using PL/SQL.

For examples sake let’s use table:

Obviously I can’t do (unless there’s some secret method) something like:

So my standard way of solving it was:

However I don’t know if it’s accepted way of doing it, or if there’s any better way of checking, I would really apprieciate if someone could share their wisdom with me.

Advertisement

Answer

I wouldn’t push regular code into an exception block. Just check whether any rows exist that meet your condition, and proceed from there:

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement