在下面的查询中有什么错误,它的抛出错误SQL错误:ORA-00933:SQL命令没有正确结束 00933. 00000 - " SQL命令未正确结束"。 想要从两个与ERROR_LOG err_payment_id匹配的表中删除所有payment_ids 请帮我纠正查询。
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);
答案 0 :(得分:2)
Oracle中需要2个delete
语句。
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);
答案 1 :(得分:0)
您无法使用SQL Server中的Join进行删除。此外,您无法使用常规删除一次从多个表中删除。相反,Make it 2 delete语句如下:
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
)
答案 2 :(得分:0)
试试这个 -
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))