Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Incorporating IF statements

Status
Not open for further replies.

LauraCairns

Programmer
Jul 26, 2004
173
0
0
GB
I have the below oracle statement and I am trying to incorporate an IF statement to see if a row exists in a table and if it does then I don't want to run a delete query however if it doesn't then I do want to do want to run the delete query.

I'm not very good with oracle and have never really used it before and was wondering if someone could give me an example of something like the query i need to produce please.

I'm not really sure what syntax to use. for the IF statement and how to check if a table contains a record.

Can someone help me please

 
You may add (not) exists condition to your query. E.g.

Code:
delete from dept d where not exists (select 1 from emp e where e.deptno=e.deptno)

Of course if you want to check record existance before deleting it the only thing you need is to refine your where clause.

Regards, Dima
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top