Solved

Nesting a select in a delete

Posted on 2004-08-03
9
1,359 Views
Last Modified: 2012-05-05
My problem is that whenever I use a nestedt select statement in my delete statment, and that select statement uses set arithmitic ie. union, minus, etc. I get an error (ORA-01732) stating that I cannot do this.  Is there some sort of easy work around without re-writing the scripts.
0
Comment
Question by:rproud
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 5

Expert Comment

by:FBIAGENT
ID: 11708486
pls post your query
0
 
LVL 35

Expert Comment

by:Mark Geerlings
ID: 11709049
You may be able to create a view that contains the "union" and/or "minus" operator, then do a simple select from the view in your sub-query for the delete statement.
0
 

Author Comment

by:rproud
ID: 11709449
don't have access to it at the moment but it was along the lines of:

(select t1.* from t1, t2
where t1.blah = t2.blah(+))
minus
(select t1.* from t1, t2
where t1.blah = t2.blah)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 35

Accepted Solution

by:
Mark Geerlings earned 125 total points
ID: 11709712
This should give you the same results (maybe faster) and avoid the "set" operator:
select * from t1 where not exists (select 1 from t2 where t2.blah = t1.blah)
0
 

Author Comment

by:rproud
ID: 11709776
ok i'll make sure i can nest that in the delete statement tomorrow and award points if it works
0
 
LVL 13

Expert Comment

by:anand_2000v
ID: 11712109
can you post your entire delete statement?
0
 

Author Comment

by:rproud
ID: 11713723
delete from ((select t1.* from t1, t2
where t1.blah = t2.blah(+))
minus
(select t1.* from t1, t2
where t1.blah = t2.blah))
0
 
LVL 11

Expert Comment

by:vc01778
ID: 11715365
Why not just:

delete from t1 where blah not in (select blah from t2);

or (as Mark suggested):

delete from t1 a where not exist (select 1  from t2 where blah=a.blah);


VC
0
 
LVL 11

Expert Comment

by:vc01778
ID: 11715494
If,  for  whatever reason, you'd like to use  'minus',  you can do this:

delete from t1 where blah  in
(
select blah from
(
select * from t1
minus
select * from t2
)
)

VC
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question