Update Oracle table with values from CSV file

前端 未结 5 2100
春和景丽
春和景丽 2020-12-19 05:18

I have a CSV file which contains an ID and several other columns. I also have a table in oracle where the ID identifies a row. How can I best replace the values that are in

5条回答
  •  轮回少年
    2020-12-19 05:55

    Use SQL*Loader

    sqlldr username@server/password control=load_csv.ctl
    

    The load_csv.ctl file

    load data
     infile '/path/to/mydata.csv'
     into table mydatatable
     fields terminated by "," optionally enclosed by '"'          
     ( empno, empname, sal, deptno )
    

    where /path/to/mydata.csv is the path to the CSV file that you need to load, on Windows something like C:\data\mydata.csv. The tablename is mydatatable. The columns are listed in order that they apear in the csv file on the last line.

    Unless you have a very large volume of data this is the easiest to maintain way of getting the data in. If the data needs to be loaded on a regular basis this can be worked into a shell script and run by CRON on a U*NX system.

提交回复
热议问题