删除由连接多个表的 select 查询获取的行

Delete Rows which are fetched by a select query joining several tables

我写了以下select:

SELECT r.ID, r.NAME, r.REMARK, u.user_id, u.deadline, u.creation_date, d.NEXT_TEST_DATE, t.TEST_INTERNAL_EXTERNAL FROM reminder r, reminder_users u, device d, device_test t where r.id = u.reminder_id and u.receipt = 0 and (regexp_replace(r.origin_values, '[^0-9]', '')) = d.id and d.NEXT_TEST_INT_ID = t.id  and t.TEST_INTERNAL_EXTERNAL = 0 and r.NAME like '%Interne%' and r.NAME not like '%Externe%' and u.deadline <> d.NEXT_TEST_DATE_INTERNAL and u.DEADLINE > sysdate GROUP BY r.ID, r.NAME, r.REMARK, u.user_id, u.deadline, u.audt_creation_date, d.NEXT_TEST_DATE_INTERNAL, t.TEST_INTERNAL_EXTERNAL ORDER BY u.deadline;

我想做的:我想删除提醒中的行,这些行是由描述的select。

我尝试了什么:

DELETE from REMINDER where id in (SELECT r.ID, r.NAME, r.REMARK, u.user_id, u.deadline, u.audt_creation_date, d.NEXT_TEST_DATE_INTERNAL, t.TEST_INTERNAL_EXTERNAL FROM reminder r, reminder_users u, device d, device_test t where r.id = u.reminder_id and u.receipt = 0 and (regexp_replace(r.origin_values, '[^0-9]', '')) = d.id and d.NEXT_TEST_INT_ID = t.id  and t.TEST_INTERNAL_EXTERNAL = 0 and r.NAME like '%Interne%' and r.NAME not like '%Externe%' and u.deadline <> d.NEXT_TEST_DATE_INTERNAL and u.DEADLINE > sysdate GROUP BY r.ID, r.NAME, r.REMARK, u.user_id, u.deadline, u.audt_creation_date, d.NEXT_TEST_DATE_INTERNAL, t.TEST_INTERNAL_EXTERNAL ORDER BY u.deadline);

结果:00907. 00000 - "missing right parenthesis"

我想知道我是否可以通过这种方式基本上删除这些行。我也试过 'exists' 导致同样的错误。

有什么建议吗?提前致谢!

从子查询中删除 order by 子句,它应该可以工作:

DELETE from BSRMD_REMINDER where id in (SELECT r.ID FROM bsrmd_reminder r, bsrmd_reminder_users u, bsdev_device d, bsdev_device_test t where r.id = u.reminder_id and u.receipt = 0 and (regexp_replace(r.origin_values, '[^0-9]', '')) = d.id and d.NEXT_TEST_INT_ID = t.id  and t.TEST_INTERNAL_EXTERNAL = 0 and r.NAME like '%Interne%' and r.NAME not like '%Externe%' and u.deadline <> d.NEXT_TEST_DATE_INTERNAL and u.DEADLINE > sysdate GROUP BY r.ID, r.NAME, r.REMARK, u.user_id, u.deadline, u.audt_creation_date, d.NEXT_TEST_DATE_INTERNAL, t.TEST_INTERNAL_EXTERNAL );

或更好地使用存在:

  DELETE from BSRMD_REMINDER 
where exists 
(
    SELECT 1 
    FROM bsrmd_reminder r, bsrmd_reminder_users u, bsdev_device d, bsdev_device_test t 
    where r.id = u.reminder_id and u.receipt = 0 and (regexp_replace(r.origin_values, '[^0-9]', '')) = d.id 
    and d.NEXT_TEST_INT_ID = t.id  and t.TEST_INTERNAL_EXTERNAL = 0 and r.NAME like '%Interne%' and r.NAME not like '%Externe%' 
    and u.deadline <> d.NEXT_TEST_DATE_INTERNAL and u.DEADLINE > sysdate 
    AND BSRMD_REMINDER.ID=r.ID
    GROUP BY r.ID, r.NAME, r.REMARK, u.user_id, u.deadline, u.audt_creation_date, 
    d.NEXT_TEST_DATE_INTERNAL, t.TEST_INTERNAL_EXTERNAL 
);

**请再次检查所有这些连接是否真的有必要。