我写了一个具有以下查询的SQL脚本。查询工作正常。
update partner set is_seller_buyer=1 where id in (select id from partner where names in ( 'A','B','C','D','E',... // around 100 names. ));
但是现在,我不想在查询本身中编写大约100个名称,而是要从CSV文件中获取所有名称。我在互联网上读到有关SQL * Loader的信息,但在更新查询上却得不到很多。我的csv文件仅包含名称。
我试过了
load data infile 'c:\data\mydata.csv' into table partner set is_wholesaler_reseller=1 where id in (select id from partner where names in ( 'A','B','C','D','E',... // around 100 names. )); fields terminated by "," optionally enclosed by '"' ( names, sal, deptno )
我怎样才能做到这一点?提前致谢。
SQL * Loader不执行更新,仅执行插入。因此,您应该将名称插入一个单独的表(例如)中names,然后从中运行更新:
names
update partner set is_seller_buyer=1 where id in (select id from partner where names in ( select names from names ));
您的加载程序脚本可以更改为:
load data infile 'c:\data\mydata.csv' into table names fields terminated by "," optionally enclosed by '"' ( names, sal, deptno )
一种替代方法是使用外部表,该表允许Oracle将平面文件当作表一样对待。在这里可以找到一个入门的示例。