SAS使用自动增量ID导出到Oracle数据库

时间:2013-12-05 16:28:05

标签: oracle sas auto-increment

我正在使用SAS Data Integration Studio 4.4。 我有一个表填充了值,我想导出到oracle数据库。 与数据库的连接和导出本身没有问题。但是“ID”列应该与每个新行一起计算。如何在SAS方面解决这个问题?

由于某些原因,我无法在数据库中为ID添加自动增量。

有什么建议吗? 提前谢谢。

1 个答案:

答案 0 :(得分:0)

在代码编辑器中,您应该可以做类似这样的事情。这些假设您已将oralib定义为与oracle的连接(在libname语句或DIS的等效语句中)。

* Get last ID in oracle into a macro variable;

proc sql;
select max(id) into :maxID from oralib.oratable;  *make these the real oracle libname and oracle table name;
quit;

*use it;
data append_to_oracle;
set your_data_set; *whatever dataset contains the data you want to insert into oracle;
ID = _n_+&maxID.; *&maxID. contains the highest ID in oracle, so this will add 1 or more to it;
run;
*you could make this a view to save processing time if that is important - like so;
*replace data line with;
*data append_to_oracle/view=append_to_oracle;

*append to oracle however you currently append;

_N_是数据步骤循环计数器,在执行简单的数据操作(始终从1开始)时,其作用类似于自动增量列。

如果您的oracle表很大,max(id)查询可能需要一段时间,您可以考虑将最大ID保存在文本文件或类似的本地文件中,这样您就不必继续查询它了。 / p>