Get the tools you need to learn Java skills fast!
Video tutorials, eBooks, hands-on lab exercises, sample code.
Get started
The moose likes JDBC and Relational Databases and the fly likes oracle equivalent to  Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Badass: Making Users Awesome this week in the Game Development forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "oracle equivalent to  "IF EXISTS"" Watch "oracle equivalent to  "IF EXISTS"" New topic

oracle equivalent to "IF EXISTS"

g forte

Joined: Aug 28, 2003
Posts: 25
Hello all,
I am trying to write a query that will check if a record exists and, if not , inserts the record in 1 trip to the db.
I have this query:

IF NOT EXISTS (Select award_number from hold_table_award WHERE award_number = 'duh') BEGIN INSERT INTO hold_table_award(award, title)VALUES(?,?)

This wont work in Oracle.
Anyone know how to make it work or if Oracle has something similar to IF NOT EXISTS

Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 31634

You can definitely use a stored procedure. I'm not sure of a way to do it using raw SQL.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
I agree. Here's the link:
subject: oracle equivalent to "IF EXISTS"