0

How to create an external table from my text file and use that to update to real table, rather than creating a (normal) staging table and using SQL*Loader.

sample.ctl

load data 
infile 'data.txt'
append into table newtable
fields terminated by '|' 
TRAILING NULLCOLS
(ACCOUNTNBR)

data.txt

some raw datas..

54545554
54542145
65656566
58787788
Dinesh Kumar
  • 1,173
  • 7
  • 19
  • 30
  • 1
    Don't repeat the question, [improve the existing one](http://stackoverflow.com/help/no-one-answers). Have you looked at the [documentation I linked to before](http://docs.oracle.com/cd/E11882_01/server.112/e22490/et_concepts.htm#SUTIL011)? What have you tried? – Alex Poole Mar 03 '14 at 14:44

1 Answers1

0
  1. The file, info.dat, created with data identified above.

  2. Set-up a default directory (which contains the data source) and to grant access to it (need the CREATE ANY DIRECTORY privilege):

    CREATE DIRECTORY ext_tab_dir AS '/usr/apps/datafiles';

    GRANT READ ON DIRECTORY ext_tab_dir TO SCHEMA_OWNER;

  3. Create an external table named newtable_load:

    CREATE TABLE newtable_load
    (ACCOUNTNBR NUMBER
    )
       ORGANIZATION EXTERNAL
       (TYPE ORACLE_LOADER
       DEFAULT DIRECTORY default_directory
       ACCESS PARAMETERS
       (RECORDS DELIMITED BY NEWLINE
        FIELDS (ACCOUNTNBR NUMBER)
       )
       LOCATION ('info.dat')
    );
    
  4. Load data from the external table newtable_load into the table newtable:

INSERT INTO newtable (ACCOUNTNBR) (SELECT ACCOUNTNBR FROM newtable_load);

Patrick Bacon
  • 4,490
  • 1
  • 26
  • 33