Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to avoid NO_DATA_FOUND when doing select?

704520Jul 15 2009 — edited Jul 15 2009
I want to check whether there is a specific record in my table. If there is, I just do some update; if not, I want to insert one.

So here I have my conditional PL/SQL
...
SELECT COUNT(*) INTO count FROM table WHERE some_condition;

IF (count == 0) THEN
--create a new record
ELSE THEN
--update the existing one
END IF;
...
However, if there is indeed no such a record, the PL/SQL will throw out a NO_DATA_FOUND exception just after the SELECT statement. So what's the proper way to write the query in my case? Thanks so much!
This post has been answered by SomeoneElse on Jul 15 2009
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 12 2009
Added on Jul 15 2009
8 comments
3,591 views