Solved

Nesting a select in a delete

Posted on 2004-08-03
9
1,347 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 34

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 34

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

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.

Join & Write a Comment

Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…

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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now