0

whats wrong in below query, its throwing error SQL Error: ORA-00933: SQL command not properly ended 00933. 00000 - "SQL command not properly ended". Want to delete all payment_ids from two tables which are matching with ERROR_LOG err_payment_id Please help me in correcting query.

TBLPAYMENT(PAYMENT_ID, OTHER COLUMNS)
TBLPAYMENT_ALT_ID (PAYMENT_ID, OTHER COLUMNS)
ERROR_LOG(ERR_PAYMENT_ID, OTHER COLUMNS)

    DELETE TBLPAYMENT, TBLPAYMENT_ALT_ID FROM TBLPAYMENT PYMT INNER JOIN 
    TBLPAYMENT_ALT_ID PAI ON PYMT.PAYMENT_ID = PAI.PAYMENT_ID 
    WHERE PYMT.PAYMENT_ID IN (SELECT ERR_PAYMENT_ID FROM ERROR_LOG);
3
  • do u want to delete only one column ? Commented Feb 19, 2018 at 12:03
  • 2
    Please don't tag irrelevant RDBMS. Commented Feb 19, 2018 at 12:03
  • Where in the Oracle Manual did you find the syntax that supports INNER JOIN in the DELETE statement? Commented Feb 19, 2018 at 12:05

3 Answers 3

2

You need 2 delete statements in Oracle.

DELETE TBLPAYMENT PYMT WHERE PYMT.PAYMENT_ID IN (SELECT ERR_PAYMENT_ID FROM ERROR_LOG);

DELETE TBLPAYMENT_ALT_ID PAI WHERE PAI.PAYMENT_ID IN (SELECT ERR_PAYMENT_ID FROM ERROR_LOG);
Sign up to request clarification or add additional context in comments.

Comments

0

You Can't delete using Join in SQL Server. Also, you can't delete from multiple tables at a time using the normal Delete. Instead, Make it 2 delete statements like this :

DELETE FROM TBLPAYMENT
       WHERE EXISTS
       (      
          SELECT 1 FROM ERROR_LOG WHERE ERR_PAYMENT_ID = TBLPAYMENT.PAYMENT_ID
       )
DELETE FROM TBLPAYMENT_ALT_ID
       WHERE EXISTS
       (      
          SELECT 1 FROM ERROR_LOG WHERE ERR_PAYMENT_ID = TBLPAYMENT_ALT_ID.PAYMENT_ID
       )

1 Comment

You can delete with a join in SQL Server, but not Oracle.
0

Try this -

DELETE from TBLPAYMENT where PAYMENT_ID in (select PYMT.PAYMENT_ID FROM TBLPAYMENT PYMT INNER JOIN 
TBLPAYMENT_ALT_ID PAI ON PYMT.PAYMENT_ID = PAI.PAYMENT_ID 
WHERE PYMT.PAYMENT_ID IN (SELECT ERR_PAYMENT_ID FROM ERROR_LOG))

DELETE from TBLPAYMENT_ALT_ID where PAYMENT_ID in (select PAI.PAYMENT_ID FROM TBLPAYMENT PYMT INNER JOIN 
TBLPAYMENT_ALT_ID PAI ON PYMT.PAYMENT_ID = PAI.PAYMENT_ID 
WHERE PYMT.PAYMENT_ID IN (SELECT ERR_PAYMENT_ID FROM ERROR_LOG))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.