Solved

Nesting a select in a delete

Posted on 2004-08-03
9
1,350 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
  • 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
 
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
Via a live example, show how to take different types of Oracle backups using RMAN.
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

932 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now