【问题标题】:Update a column in table using SQL*Loader?使用 SQL*Loader 更新表中的列?
【发布时间】:2012-02-01 05:18:52
【问题描述】:

我编写了一个具有以下查询的 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 oracle sql-loader


    【解决方案1】:

    SQL*Loader 不执行更新,只执行插入。因此,您应该将您的姓名插入到单独的表中,例如 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 将平面文件视为表。可以在here 找到一个帮助您入门的示例。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多