Solved

Nesting a select in a delete

Posted on 2004-08-03
9
1,357 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Suggested Solutions

Title # Comments Views Activity
dbms_crypto.decrypt   errors out 6 47
format dd/mm/yyyy parameter 16 49
Error in creating a view. 8 35
Pivoting oracle table 9 75
I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that useā€¦
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

730 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