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:
    shell> 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:
    shell> sqlldr C##user_id/password@xe control=customers.ctl 

Automating the Job Fully
Further automate the whole procedure by using shell programming:
shell> cat dbload.sh 
sqlplus C##user_id/password@xe @create.sql
sqlldr  C##user_id/password@xe control=customers.ctl
shell> sh dbload.sh 



      Mum’s the word.