Vous êtes sur la page 1sur 3

Creating a SQL Loader file: Requirements: 1 CSV file (.csv) or Text file (.

txt) that we need to load onto a specific table. 2 Control file (.ctl) which will house the SQL Loader script. 3 Log file (.log) which will contain the log of the .ctl file executed Creating the control file for SQL Loader: Open New file in Editplus or Notepad Type the following as rerquired: ************************************************************************* START OF FILE ************************************************************************ ******** 1 2 3 4 5 6 NG NULLCOLS 7 LOAD DATA INFILE 'D:topup_value_pack_cdma.csv' BADFILE 'D:\topup_value_pack_cdma.bad' DISCARDFILE 'D:\topup_value_pack_cdma.dsc' INSERT INTO TABLE MERAPACK_CDMA FIELDS TERMINATED BY "|" OPTIONALLY ENCLOSED BY "

" TRAILI

(CIRCLE,MRP,R2R_LOCAL,R2O_LOCAL,R2R_STD,R2O_STD,VALIDITY)

************************************************************************* END OF FILE ************************************************************************** ****** EXPLAINATION (as per the line number assigned to each line': 1 The LOAD DATA statement is required at the beginning of the cont rol file. 2 The INFILE option specifies where the input file is located

3 Specifying BADFILE is optional. If you specify, then bad record s found during loading will be stored in this file. 4 Specifying DISCARDFILE is optional. If you specify, then records which do not meet a WHEN condition will be written to this file. 5 You can use any of the following loading option INSERT : Loads rows only if the target table is empty APPEND: Load rows if the target table is empty or not. REPLACE: First deletes all the rows in the existing tabl e and then, load rows. TRUNCATE: First truncates the table and then load rows. This line indicates how the fields are separated in input file. Since in our case the fields are separated by "," so we have spe cified "," as the terminating char for fields. You can replace this by any char which is used to terminate fiel ds. Some of the popularly use terminating characters are semicolon " ;", colon ":", pipe "|" etc. 6

TRAILING NULLCOLS means if the last column is null then treat th is as null value. Otherwise, SQL LOADER will treat the record as bad if the last column is null. 7 In this line specify the columns of the target table. Note how d o you specify format for Date columns Save the file as "topup_value_pack_cdma.ctl". In this case we are saving in D:\ for ease of use, else any other destination is good. Go to commmand promt C:\>sqlldr scott/tiger@orcl control='D:\topup_value_pack_cdma.ctl' log='D:\topup _value_pack_cdma.log' SQL*Loader: Release 10.2.0.1.0 - Production on Wed Mar 14 15:46:37 2012 Copyright (c) 1982, 2005, Oracle. All rights reserved. Commit point reached - logical record count 42 The LOG file will contain the following details: ************************************************************************* START OF FILE ************************************************************************ ******** SQL*Loader: Release 10.2.0.1.0 - Production on Wed Mar 14 15:46:37 2012 Copyright (c) 1982, 2005, Oracle. All rights reserved. Control File: D:\topup_value_pack_cdma.ctl Data File: D:\topup_value_pack_cdma.csv Bad File: D:\topup_value_pack_cdma.bad Discard File: D:\topup_value_pack_cdma.dsc (Allow all discards) Number to load: Number to skip: Errors allowed: Bind array: Continuation: Path used: ALL 0 50 64 rows, maximum of 256000 bytes none specified Conventional

Table MERAPACK_CDMA, loaded from every logical record. Insert option in effect for this table: INSERT TRAILING NULLCOLS option in effect Column Name Position Len Term Encl Datatype ------------------------------ ---------- ----- ---- ---- --------------------CIRCLE FIRST * | O(X09) CHARACTER MRP R2R_LOCAL R2O_LOCAL NEXT NEXT NEXT * * * | O(X09) CHARACTER | O(X09) CHARACTER | O(X09) CHARACTER

R2R_STD R2O_STD VALIDITY

NEXT NEXT NEXT

* * *

| O(X09) CHARACTER | O(X09) CHARACTER | O(X09) CHARACTER

Record 1: Rejected - Error on table MERAPACK_CDMA, column CIRCLE. ORA-12899: value too large for column "NETWORKKPI"."MERAPACK_CDMA"."CIRCLE" (act ual: 7, maximum: 5) Table MERAPACK_CDMA: 41 Rows successfully loaded. 1 Row not loaded due to data errors. 0 Rows not loaded because all WHEN clauses were failed. 0 Rows not loaded because all fields were null. Space allocated for bind array: Read buffer bytes: 1048576 Total Total Total Total logical logical logical logical records records records records skipped: read: rejected: discarded: 0 42 1 0 115584 bytes(64 rows)

Run began on Wed Mar 14 15:46:37 2012 Run ended on Wed Mar 14 15:46:38 2012 Elapsed time was: CPU time was: 00:00:00.22 00:00:00.10

************************************************************************* END OF FILE ************************************************************************** ******