Pages

Saturday, February 05, 2011

Using External Table

1- Create the CSV File on some location using excel
1,ABC,100
2,DEF,200
3,IJK,300

2- Create directory in the database using the location as step 1
CREATE OR REPLACE DIRECTORY
TEST_DIR AS
'd:\test_dir';
3- Grant appropriate privs to the user
GRANT READ, WRITE ON DIRECTORY SYS.TEST_DIR TO SCOTT;
4- Create the table

create table home.ext_table_csv (
  c1   Number,
  c2   Varchar2(20),
  c3   number(20)
)
organization external (
  type              oracle_loader
  default directory test_dir
  access parameters (
    records delimited  by newline
    fields  terminated by ','
    missing field values are null
  )
  location ('testcsv.csv')
)
reject limit unlimited;
5- Test the table
select * from home.ext_table_csv

No comments:

Post a Comment