Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2010
    Posts
    3

    Unanswered: load data from CSV files to oracle schema

    Hi
    I have to load some ten csv files to 10 different tables in a particular schema say TEST. Is there any way to automate it, instead of writing 10 different control files for each pair of CSV file and table.

    I am using sqlldr to load the tables.

    sqlldr $usrpass $ctlfile log=$logfile bad=$badfile data=$datfile discard=$dscfile

    For example..
    have some 25 input CSV files which has over 30 coulumns in each input CSV file.
    for example if i start writing control file like this ..

    LOAD DATA
    APPEND
    INTO TABLE emp
    (empno POSITION(01:04) INTEGER EXTERNAL,
    ename POSITION(06:15) CHAR,
    job POSITION(17:25) CHAR,
    mgr POSITION(27:30) INTEGER EXTERNAL,
    sal POSITION(32:39) DECIMAL EXTERNAL,
    comm POSITION(41:48) DECIMAL EXTERNAL,
    deptno POSITION(50:51) INTEGER EXTERNAL

    and so on for 30 coulmns then the effort would be too much to create 25 control files to load 25 tables.
    I feel it would be better if i have one control file so that i can pass the table name as parameter and call the same control file in a loop.

    PS: each table has unique column names.

  2. #2
    Join Date
    Jun 2004
    Location
    Liverpool, NY USA
    Posts
    2,509
    Are the 25 files the same structure?
    Bill
    You do not need a parachute to skydive. You only need a parachute to skydive twice.

  3. #3
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    >I have to load some ten csv files to 10 different tables
    You'll need 1 control file for every table.
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  4. #4
    Join Date
    Jan 2010
    Posts
    3
    all the tables have different structure. Of course, the easiet method is to write 25 control files . but is there any way to make the work easier. Like few of them suggested stored procedure.. few said it can be achieved through external tables. Im not aware of both.. wat are its positives and negatives..

  5. #5
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    In the time you've spent looking for the lazy man's solution, you could have written the 10 control files.

    SQL> DESC TABLE1

    above does much of the heavy lifting for each table
    Do a control file for 1 table & the rest are like using a cookie cutter; just CUT & PASTE
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •