Populating a Database


Using the SQL*Loader
The SQL*Loader is a utility program that reads operating system text files and converts the contents into fields in a table. Take the following three steps to use the SQL*Loader:
  1. Delete all rows of tables and commit if it is not for appending:
    SQL> DROP TABLE  customers; 
    SQL> CREAT TABLE  customers ( 
      2    name  VARCHAR(32), 
      3    SSN   CHAR(10)  PRIMARY KEY, 
      4    no    INTEGER   CHECK (no >= 0) ); 
    SQL> COMMIT; 
  2. Create a control file:
    undcemcs02> cat customers.ctl 
    
    load data infile *
    append into table customers
    fields terminated by ',' (name, SSN, no)
    begindata
    Digimon,456789012,6
    Dragonball Z,678901234,59
    Kids Next Door,789012345,0
    Medabot,567890123,26
    Pokemon,345678901,2
    Powerpuff Girls,123456789,12
    Yu-Gi-Oh,234567890,75
    

  3. Run the loader:
    undcemcs02> sqlldr C##user.id/password@//65.52.222.73:1521/cdb1 \ 
                control=customers.ctl 

Automating the Job Fully
Further automate the whole procedure by using shell programming:
undcemcs02> cat dbload.sh 
sqlplus C##user.id/password@//65.52.222.73:1521/cdb1 @create.sql
sqlldr  C##user.id/password@//65.52.222.73:1521/cdb1 control=customers.ctl
undcemcs02> sh dbload.sh 



      Mum’s the word.