我有一个 Oracle 表,其中有 1M 行。我在 SAS 中有一个 oracle 表的子集,其中有 3000 行。我想从oracle表中删除这3000行。
Oracle Table columns are
Col1 Col2 Col3 timestamp
SAS Table columns are:
Col1 Col2 Col3
Oracle 表唯一的附加列是时间戳。这是我当前使用的代码,但需要花费很多时间。
libname ora oracle user='xxx' password='ppp' path = abcd;
PROC SQL;
DELETE from ora.oracle_table a
where exists (select * from sas_table b where a.col1=B.col1 AND a.col2=B.col2 AND A.col3=B.col3 );
QUIT;
请告知如何使其更快、更高效。
谢谢!
最佳答案
一种选择是将 SAS 表推送到 Oracle,然后使用 Oracle 端命令执行删除。我不确定 SAS 如何将上述代码转换为特定于 DBMS 的代码,但它可能会通过网络推送大量数据,具体取决于它如何优化查询;特别是,如果它必须在本地而不是在数据库上执行联接,那将非常昂贵。此外,Oracle 可能可以使用完全 native 操作更快地完成删除。
IE:
libname ora ... ;
data ora.gtt_tableb; *or create a temporary or GT table in Oracle and insert into it via proc sql;
set sas_tableb;
run;
proc sql;
connect to oracle (... );
execute (
delete from ...
) by connection to oracle;
quit;
与使用 LIBNAME 连接相比,这可能会带来显着的性能改进。
如果您充分利用 PK 的索引(如果您还没有的话),可能会有进一步的改进。
关于sql - 使用 SAS 表删除 Oracle 数据库中的特定行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25493055/