?
Solved

SQL PLUS 4 table join by delimited list

Posted on 2003-02-26
2
Medium Priority
?
1,010 Views
Last Modified: 2013-12-12
I need to delete items in on table based on values linked thru 3 other tables.  I tried this, which was too slow:

DELETE  FROM PP_REQUIREMENT_DETAILS      
WHERE RESOURCE_REQUIREMENT_ID IN
     (SELECT rr.RESOURCE_REQUIREMENT_ID
     FROM    PP_RESOURCE_REQUIREMENTS        rr      
     WHERE     rr.Task_ID                          IN        
                                                               (SELECT TASK_ID
                                                               FROM PA_TASKS
                                                               WHERE PROJECT_ID IN
                                                                          (SELECT PROJECT_ID
                                                                       FROM PA_PROJECTS
                                                                       WHERE PROJECT_NUMBER IN
               (     '20519',
                    '20307',
                    '20287',
                    '1747.04',
                    '1747.03',))))


Then I tried this:

DELETE  FROM PP_REQUIREMENT_DETAILS WHERE RESOURCE_REQUIREMENT_ID IN (SELECT rr.RESOURCE_REQUIREMENT_ID FROM PP_RESOURCE_REQUIREMENTS rr WHERE rr.Task_ID IN (SELECT TASK_ID FROM PA_TASKS WHERE PROJECT_ID IN (SELECT PROJECT_ID FROM PA_PROJECTS WHERE PROJECT_NUMBER = '20519')))/
DELETE  FROM PP_REQUIREMENT_DETAILS WHERE RESOURCE_REQUIREMENT_ID IN (SELECT rr.RESOURCE_REQUIREMENT_ID FROM PP_RESOURCE_REQUIREMENTS rr WHERE rr.Task_ID IN (SELECT TASK_ID FROM PA_TASKS WHERE PROJECT_ID IN (SELECT PROJECT_ID FROM PA_PROJECTS WHERE PROJECT_NUMBER = '20307')))/
DELETE  FROM PP_REQUIREMENT_DETAILS WHERE RESOURCE_REQUIREMENT_ID IN (SELECT rr.RESOURCE_REQUIREMENT_ID FROM PP_RESOURCE_REQUIREMENTS rr WHERE rr.Task_ID IN (SELECT TASK_ID FROM PA_TASKS WHERE PROJECT_ID IN (SELECT PROJECT_ID FROM PA_PROJECTS WHERE PROJECT_NUMBER = '20287')))/
DELETE  FROM PP_REQUIREMENT_DETAILS WHERE RESOURCE_REQUIREMENT_ID IN (SELECT rr.RESOURCE_REQUIREMENT_ID FROM PP_RESOURCE_REQUIREMENTS rr WHERE rr.Task_ID IN (SELECT TASK_ID FROM PA_TASKS WHERE PROJECT_ID IN (SELECT PROJECT_ID FROM PA_PROJECTS WHERE PROJECT_NUMBER = '1747.04')))/
DELETE  FROM PP_REQUIREMENT_DETAILS WHERE RESOURCE_REQUIREMENT_ID IN (SELECT rr.RESOURCE_REQUIREMENT_ID FROM PP_RESOURCE_REQUIREMENTS rr WHERE rr.Task_ID IN (SELECT TASK_ID FROM PA_TASKS WHERE PROJECT_ID IN (SELECT PROJECT_ID FROM PA_PROJECTS WHERE PROJECT_NUMBER = '1747.03')))/


This is multiple delete statements for each value.  The slash should probably a semicolon.  But, I can't get it to work in SQL PLUS.  I need the correct syntax and options to run multiple statements in a block like this in SQL PLUS.  

Or - perhaps there's a better way.
0
Comment
Question by:Jon_Raymond
[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
2 Comments
 
LVL 8

Accepted Solution

by:
Danielzt earned 800 total points
ID: 8029628
2 ways for you:

1:(supposed way) save these comands into a file, let's say  DEL_COM.sql.
 then you can start sql*plus,
 SQL>@DEL_COM.sql

DELETE  FROM PP_REQUIREMENT_DETAILS WHERE RESOURCE_REQUIREMENT_ID IN (SELECT rr.RESOURCE_REQUIREMENT_ID FROM PP_RESOURCE_REQUIREMENTS rr WHERE rr.Task_ID IN (SELECT TASK_ID FROM PA_TASKS WHERE PROJECT_ID IN (SELECT PROJECT_ID FROM PA_PROJECTS WHERE PROJECT_NUMBER = '20519')));
/
DELETE  FROM PP_REQUIREMENT_DETAILS WHERE RESOURCE_REQUIREMENT_ID IN (SELECT rr.RESOURCE_REQUIREMENT_ID FROM PP_RESOURCE_REQUIREMENTS rr WHERE rr.Task_ID IN (SELECT TASK_ID FROM PA_TASKS WHERE PROJECT_ID IN (SELECT PROJECT_ID FROM PA_PROJECTS WHERE PROJECT_NUMBER = '20307')));
/
DELETE  FROM PP_REQUIREMENT_DETAILS WHERE RESOURCE_REQUIREMENT_ID IN (SELECT rr.RESOURCE_REQUIREMENT_ID FROM PP_RESOURCE_REQUIREMENTS rr WHERE rr.Task_ID IN (SELECT TASK_ID FROM PA_TASKS WHERE PROJECT_ID IN (SELECT PROJECT_ID FROM PA_PROJECTS WHERE PROJECT_NUMBER = '20287')));
/
DELETE  FROM PP_REQUIREMENT_DETAILS WHERE RESOURCE_REQUIREMENT_ID IN (SELECT rr.RESOURCE_REQUIREMENT_ID FROM PP_RESOURCE_REQUIREMENTS rr WHERE rr.Task_ID IN (SELECT TASK_ID FROM PA_TASKS WHERE PROJECT_ID IN (SELECT PROJECT_ID FROM PA_PROJECTS WHERE PROJECT_NUMBER = '1747.04')));
/
DELETE  FROM PP_REQUIREMENT_DETAILS WHERE RESOURCE_REQUIREMENT_ID IN (SELECT rr.RESOURCE_REQUIREMENT_ID FROM PP_RESOURCE_REQUIREMENTS rr WHERE rr.Task_ID IN (SELECT TASK_ID FROM PA_TASKS WHERE PROJECT_ID IN (SELECT PROJECT_ID FROM PA_PROJECTS WHERE PROJECT_NUMBER = '1747.03')));
/

2: start SQL*PLUS
sql> begin
2  ..... enter all your commands here,line by line, no slash ....
3
 DELETE  FROM PP_REQUIREMENT_DETAILS WHERE RESOURCE_REQUIREMENT_ID IN (SELECT rr.RESOURCE_REQUIREMENT_ID FROM PP_RESOURCE_REQUIREMENTS rr WHERE rr.Task_ID IN (SELECT TASK_ID FROM PA_TASKS WHERE PROJECT_ID IN (SELECT PROJECT_ID FROM PA_PROJECTS WHERE PROJECT_NUMBER = '20519')));
DELETE  FROM PP_REQUIREMENT_DETAILS WHERE RESOURCE_REQUIREMENT_ID IN (SELECT rr.RESOURCE_REQUIREMENT_ID FROM PP_RESOURCE_REQUIREMENTS rr WHERE rr.Task_ID IN (SELECT TASK_ID FROM PA_TASKS WHERE PROJECT_ID IN (SELECT PROJECT_ID FROM PA_PROJECTS WHERE PROJECT_NUMBER = '20307')));
...

end;
/

(pay attention the laste two lines)


0
 
LVL 4

Expert Comment

by:stemu2000
ID: 8029874

direct joins are better in most cases:


DELETE PP_REQUIREMENT_DETAILS rd
WHERE exists (
    (SELECT  1
     FROM    PP_RESOURCE_REQUIREMENTS  rr,
             PA_TASKS t,
             PA_PROJECTS pap
     WHERE   rd.RESOURCE_REQUIREMENT_ID = rr.RESOURCE_REQUIREMENT_ID
      and    rr.Task_ID = t.TASK_ID
      and    t.PROJECT_ID = pap.PROJECT_ID
      and    pap.PROJECT_NUMBER IN
              (    '20519',
                   '20307',
                   '20287',
                   '1747.04',
                   '1747.03',))))


Cheers, Stefan
0

Featured Post

Technology Partners: 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!

Question has a verified solution.

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

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…
Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
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.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Suggested Courses

777 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