2012-02-01 96 views
5

我已經寫了一個SQL腳本,具有以下查詢。 查詢工作正常。使用SQL * Loader更新表中的列?

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文件只包含名稱。

enter image description here

我已經試過

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) 

我怎樣才能做到這一點? 在此先感謝。

回答

5

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

相關問題