0

My delete statement returns a 933 error in Oracle, I'm not sure what is wrong-

DELETE b
from temp a
JOIN
  fact_tab b
on a.col1 = b.col1
and a.col2 = b.col2
and a.col3 = b.col3; 

Both tables dont have a primary key. select statement on the same thing works-

select * 
from temp a
JOIN
  fact_tab b
on a.col1 = b.col1
and a.col2 = b.col2
and a.col3 = b.col3; 
user2441441
  • 1,237
  • 4
  • 24
  • 45
  • 4
    Where in the manual did you find the syntax to use a `JOIN` for a `DELETE` statement? https://docs.oracle.com/cd/E11882_01/server.112/e41084/statements_8005.htm#SQLRF01505 –  Feb 20 '15 at 07:05
  • My mistake, I am not deeply familiar with Oracle. How would I accomplish this? – user2441441 Feb 20 '15 at 07:07
  • http://stackoverflow.com/search?q=%5Boracle%5D+delete+join –  Feb 20 '15 at 07:08

2 Answers2

3

try this

DELETE FROM
  fact_tab
WHERE
  EXISTS
  (
    SELECT
      1
    FROM
      temp
    WHERE
      temp.col1 = fact_tab.col1 AND
      temp.col2 = fact_tab.col2 AND
      temp.col2 = fact_tab.col2
  )
Okdel
  • 183
  • 1
  • 5
1

Oracle doesn't allow JOIN in a DELETE statement directly like that.

You could do the delete in the following way:

DELETE
FROM fact_tab
WHERE ROWID IN
  (SELECT b.rowid
  FROM temp a
  JOIN fact_tab b
  ON a.col1  = b.col1
  AND A.col2 = b.col2
  AND A.col3 = b.col3
  );

You could also use WHERE EXISTS clause.

Lalit Kumar B
  • 47,486
  • 13
  • 97
  • 124