我正在做这个简单的交易:
DELETE FROM ominve01
WHERE CVE_OBS IN (SELECT CVE_OBS
FROM minve01 M
WHERE M.FECHA_DOCU < '31.12.2010'
OR FECHA_DOCU > '31.12.2015')
但完成删除大约需要2个半小时。我的查询不好吗?我怎样才能改善它?
或如何提高交易速度?
答案 0 :(得分:1)
DELETE FROM ominve01 N
WHERE
exists(SELECT * FROM minve01 M
WHERE M.FECHA_DOCU < '31.12.2010'
OR FECHA_DOCU > '31.12.2015' and
N.CVE_OBS=M.CVE_OBS)
或执行块(您需要更正变量类型)
execute block
as
declare variable v integer;
begin
for SELECT M.CVE_OBS
FROM minve01 M
WHERE M.FECHA_DOCU < '31.12.2010'
OR FECHA_DOCU > '31.12.2015'
into :v do delete from ominve01 WHERE CVE_OBS=:v;
end