Sql Loader loading separate date parts into a date

Hello,
I'm having a question on SQL Loader.
Suppose I have a flat file with a format:
"John Jackson", 2007, 12, 31, 23, 59, 01
"William Smith", 2007, 12, 31, 23, 59, 02
"Tracy vanDijk", 2007, 12, 31, 23, 59, 03
And I like to put it in a table TEST with (name varchar(20), mydate date).
The problem is: how to create a control file for sqlLoader that converts the seperate date-elements into a date field?
load data
infile 'mydata.csv'
badfile 'badfile.log'
discardfile 'discardfile.log'
append
into table TEST
fields terminated by "," optionally enclosed by '"'          
( name, mydate ????)
I'd like to put it in one step into a date field, and not using seperate tables, stored procedures, triggers and such. I think it must be possible, but I wasn't able to find a working example thus far.
Hope you can help me out.

A colleague came up with the BOUNDFILLER option. Searching again on the forum I created the solution, that I'd like to share with you.
SQL> create table TEST1 (naam varchar(30), meetdatum date);
Tabel is aangemaakt.
mydata.csv:
"Scott Tiger", 2006, 02, 18, 23, 59, 4
"Frank Naude", 2007, 12, 31, 18, 00, 59
"Fou TeDatum", 2007, 02, 31, 01, 10, 5
"Johnny Smith", 2007, 1, 1, 12, 00 , 00
laden.ctl:
load data
infile 'mydata.csv'
badfile 'badfile.log'
discardfile 'discardfile.log'
into table test1
fields terminated by "," optionally enclosed by '"'     
trailing nullcols     
( naam
,b_yyyy boundfiller char
,b_mm boundfiller char
,b_dd boundfiller char
,b_hh24 boundfiller char
,b_mi boundfiller char
,b_ss boundfiller char
,meetdatum "to_date(:b_yyyy || :b_mm || :b_dd || :b_hh24 || :b_mi || :b_ss , 'YYYYMMDDHH24MISS')"
SQL> alter session set nls_date_format = 'YYYY-MM-DD:HH24:MI:SS' ;
SQL> select * from test1;
NAAM MEETDATUM
Scott Tiger 2006-02-18:23:59:04
Frank Naude 2007-12-31:18:00:59
Johnny Smith 2007-11-12:00:00:00
The wrong date, Feb 31st, is spooled to the badfile.

Similar Messages

  • SQL*Loader Sequential Data File Record Processing?

    If I use the conventional path will SQL*Loader process a data file sequentially from top to bottom?  I have a file comprised of header and detail records with no value found in the detail records that can be used to relate to the header records.  The only option is to derive a header value via a sequence (nextval) and then populate the detail records with the same value pulled from the same sequence (currval).  But for this to work SQL*Loader must process the file in the exact same sequence that the data has been written to the data file.  I've read through the 11g Oracle® Database Utilities SQL*Loader sections looking for proof that this is what will happen but haven't found this information and I don't want to assume that SQL*Loader will always process the data file records sequentially.
    Thank you

    Oracle Support responded with the following statement.
    "Yes, SQL*LOADER process data file from top to bottom.
    This was touched in the note below:
    SQL*Loader - How to Load a Single Logical Record from Physical Records which Include Linefeeds (Doc ID 160093.1)"
    Jason

  • SQL*Loader and data enclosed by single quotes

    Hello,
    I need to migrate some data from Sybase to Oracle. Can't use the Migration Workbench because this is Sybase's SQL Anywhere product. We are therefore trying to load via SQL*Loader.
    Sybase outputs its data into text files and encloses it with single quotes, like:
    'ABC123',
    'UR94LL',
    '7YUHII'
    We are running into a problem because we cannot figure out how to use the OPTIONALLY ENCLOSED BY parameter with single quotes. If we just use the FIELDS TERMINATED BY parameter, then the entire string, including the quotation marks, gets loaded into the Oracle table. This causes bad records to be created when the data is exactly the length of the column width - the two quotation markss make the field longer than is allowed in the table. Plus - the data shouldn't have quotes around it in normal situations.
    We can do 'Find and Replace' to replace the single quotation marks with double quotations, but some of the Sybase tables are huge, and we'd like to avoid having to open and edit them. However, if this is the only way to go, then we'll have to use it. I just wondered whether anyone had run into this before and been able to solve it.
    Thanks.
    -melissa

    We are running into a problem because we cannot figure out how to use the OPTIONALLY ENCLOSED BY parameter with single quotesTry
    OPTIONALLY ENCLOSED BY X'27'http://download-uk.oracle.com/docs/cd/B10501_01/server.920/a96652/ch06.htm#1015083

  • SQL Loader - CSV Data file with carraige returns and line fields

    Hi,
    I have a CSV data file with occasional carraige returns and line feeds in between, which throws my SQL loader script off. Sql loader, takes the characters following the carraige return as a new record and gives me error. Is there a way I could handle carraige returns and linefeeds in SQL Loader.
    Please help. Thank you for your time.
    This is my Sql Loader script.
    load data
    infile 'D:\Documents and Settings\user1\My Documents\infile.csv' "str '\r\n'"
    append
    into table MYSCHEMA.TABLE1
    fields terminated by ','
    OPTIONALLY ENCLOSED BY '"'
    trailing nullcols
    ( NAME CHAR(4000),
    field2 FILLER,
    field3 FILLER,
    TEST DEPT CHAR(4000)
    )

    You can "regexp_replace" the columns for special characters

  • SQL Loader deletes data, after reporting a file not found error

    I have several control files beginning:
    LOAD DATA
    INFILE <dataFile>
    REPLACE INTO TABLE <tableName>
    FIELDS TERMINATED BY '<separator>'
    When running SQL Loader, in the case of one particular control file, if the file referenced does not exist, SQL Loader first reports that the file could not be found, but then proceeds to delete all the data in the table in which the import was meant to take place. The corresponding log file reveals that the file could not be found, but also states that 0 records were loaded and 0 records were skipped.
    In the case of all other control files, if the file is not found, the log files simply report this exception but do not show any statisitcs about the number of records loaded/skipped nor does SQL Loader delete the data in any of the referenced tables. This is obviously the expected behaviour.
    Why is SQL Loader deleting the data referenced by one particular control file, even though this file does not exist and the corresponding log file has correctly picked up on this?

    in the ressource name box of your file model, when you push the search button ("...") do you see the file ?
    Cause the problem can occur when you write directly the path without selectionning the file with the assistant.
    Try this.
    I think too that that you can't see the data by right clicking and selectionning View Data ?
    Let me know the avancement...

  • Sql loader maximum data file size..?

    Hi - I wrote sql loader script runs through shell script which will import data into table from CSV file. CSV file size is around 700MB. I am using Oracle 10g with Sun Solaris 5 environment.
    My question is, is there any maximum data file size. The following code from my shell script.
    SQLLDR=
    DB_USER=
    DB_PASS=
    DB_SID=
    controlFile=
    dataFile=
    logFileName=
    badFile=
    ${SQLLDR} userid=$DB_USER"/"$DB_PASS"@"$DB_SID \
              control=$controlFile \
              data=$dataFile \
              log=$logFileName \
              bad=$badFile \
              direct=true \
              silent=all \
              errors=5000Here is my control file code
    LOAD DATA
    APPEND
    INTO TABLE KEY_HISTORY_TBL
    WHEN OLD_KEY <> ''
    AND NEW_KEY <> ''
    FIELDS TERMINATED BY ','
    TRAILING NULLCOLS
            OLD_KEY "LTRIM(RTRIM(:OLD_KEY))",
            NEW_KEY "LTRIM(RTRIM(:NEW_KEY))",
            SYS_DATE "SYSTIMESTAMP",
            STATUS CONSTANT 'C'
    )Thanks,
    -Soma
    Edited by: user4587490 on Jun 15, 2011 10:17 AM
    Edited by: user4587490 on Jun 15, 2011 11:16 AM

    Hello Soma.
    How many records exist in your 700 MB CSV file? How many do you expect to process in 10 minutes? You may want to consider performing a set of simple unit tests with 1) 1 record, 2) 1,000 records, 3) 100 MB filesize, etc. to #1 validate that your shell script and control file syntax function as expected (including the writing of log files, etc.), and #2 gauge how long the processing will take for the full file.
    Hope this helps,
    Luke
    Please mark the answer as helpful or answered if it is so. If not, provide additional details.
    Always try to provide actual or sample statements and the full text of errors along with error code to help the forum members help you better.

  • SQL Loader - Conditional Data Loading

    Hello Friends,
    I am trying to use SQL Loader to load the following records in to the Emp table (columns being - empno, ename, job, mgr, hiredate, sal, comm, deptno ).
    7876,ADAMS,CLERK,7788,"23-MAY-87",1100,,20
    7900,JAMES,CLERK,7698,"03-DEC-81",950,,30
    7902,FORD,ANALYST,7566,"03-DEC-81",3000,,20
    7934,MILLER,CLERK,7782,"23-JAN-82",1300,,10
    I want to put a condition that the data should be loaded only when the 5th field in the record (i.e, the Hiredate field) should be greater than "01-JAN-82". So with this condition, the only records to be loaded are the 1st, and the 4th one... the other two records have the hiredates being less than "01-JAN-82".
    load data
    infile 'c:\mydata.csv'
    into table emp1
    when .....
    fields terminated by "," optionally enclosed by '"'          
    ( empno, ename, job, mgr, hiredate, sal, comm, deptno )
    I am unable to put the when condition in the control file above and would be grateful if you kindly can give me some pointer as to how to achieve this.
    Thanks and Regards.
    Edited by: user645883 on Dec 29, 2008 12:45 AM

    Hello Friends,
    Thanks for your replies.
    The examples only show the when clauses where we can only use "=" or "<>" in the clause. I am trying to see if we can use ">=" or "<=" in the when clause to load the conditional data. Also trying to find out if date fields can be compared in the when clause. I am unable to do so till now and it throws syntax errors everytime
    I am able to test the when with string literals and with "=" and "<>" conditions though.
    Please help.
    Thanks & Regards.

  • SQL Loader: ignore data field

    Hi,
    in a SQL Loader control file, how do you specify that you do not wish to load a particular field?
    E.g. if I wanted to ignore the second field in the data file and load the first and third fields into a table, how would I modify the control file below?
    Thanks.
    load data
    infile 'example.dat'
    into table example
    fields terminated by ',' optionally enclosed by '"'
    col1 char,
    ignore char,
    col2 char
    )

    User FILLER keyword:
    col1 char,
    ignore filler char,
    col2 char
    )

  • SQL Loader with date formatting

    Hi,
    I'm trying to get sql loader to insert a date into a column. After much browsing, reading trial and error I still get an array of errors.
    I'm using oracle XE
    my control file looks like this
    LOAD DATA
    INFILE 'posmeters/meters.csv'
    INTO TABLE position_meters
    FIELDS terminated by ","
    ID CONSTANT '0',
    POSITION_ID,
    DATETIME DATE "DD/MM/YYYY HH24:MI:SS",
    CASH_IN,
    CASH_OUT,
    NOTES_IN,
    CHANGE_OUT,
    WINNINGS,
    VTP,
    REFILL,
    TOKEN_IN,
    TOKEN_OUT,
    ELEC_PAY,
    ELEC_CREDIT,
    REMOTE_PAY,
    REMOTE_CREDIT,
    INSERT_TS EXPRESSION "TO_CHAR(SYSDATE, 'DD/MM/YYYY HH24:MI:SS')",
    FIFTY_PND,
    TWENTY_PND,
    TEN_PND,
    FIVE_PND,
    TWO_PND,
    ONE_PND,
    FIFTY_P,
    TWENTY_P,
    TEN_P,
    FIVE_P
    It is the DATETIME field which gives me grief. I have a test data file that looks like this
    0,1010,29/09/2011 10:23:24,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24
    and my table is defined as follows
    ID NUMBER NOT NULL,
    POSITION_ID NUMBER,
    DATETIME TIMESTAMP(6) DEFAULT localTIMESTAMP NOT NULL,
    CASH_IN NUMBER,
    CASH_OUT NUMBER,
    NOTES_IN NUMBER,
    CHANGE_OUT NUMBER,
    WINNINGS NUMBER,
    VTP NUMBER,
    REFILL NUMBER,
    TOKEN_IN NUMBER DEFAULT (0) NOT NULL,
    TOKEN_OUT NUMBER DEFAULT (0) NOT NULL,
    ELEC_PAY NUMBER DEFAULT (0) NOT NULL,
    ELEC_CREDIT NUMBER DEFAULT (0) NOT NULL,
    REMOTE_PAY NUMBER DEFAULT (0) NOT NULL,
    REMOTE_CREDIT NUMBER DEFAULT (0) NOT NULL,
    INSERT_TS TIMESTAMP(6) DEFAULT (localtimestamp) NOT NULL,
    FIFTY_PND NUMBER DEFAULT 0,
    TWENTY_PND NUMBER DEFAULT 0,
    TEN_PND NUMBER DEFAULT 0,
    FIVE_PND NUMBER DEFAULT 0,
    TWO_PND NUMBER DEFAULT 0,
    ONE_PND NUMBER DEFAULT 0,
    FIFTY_P NUMBER DEFAULT 0,
    TWENTY_P NUMBER DEFAULT 0,
    TEN_P NUMBER DEFAULT 0,
    FIVE_P NUMBER DEFAULT 0
    I have tried defining the control file with
    DATETIME DATE "DD/MM/YYYY HH24:MI:SS",
    DATETIME EXPRESSION "TO_DATE(:DATETIME, 'DD/MM/YYYY HH24:MI:SS')",
    DATETIME EXPRESSION "TO_TIMESTAMP(:DATETIME, 'DD/MM/YYYY HH24:MI:SS')",
    I get errors such as
    Record 1: Rejected - Error on table "SITE_MAIN"."POSITION_METERS", column DATETIME.
    ORA-01861: literal does not match format string
    SQL*Loader-291: Invalid bind variable DATETIME in SQL string for column DATETIME.
    any help would greatfully appreciated.

    It seems that the problem was caused by the constant at the beginning of the record and had nothing to do with date formats.
    My control file now looks like this
    LOAD DATA
    INFILE 'posmeters/meters.csv'
    APPEND INTO TABLE position_meters
    FIELDS terminated by ","
    POSITION_ID          ,
    DATETIME      date "DD/MM/YYYY HH24:MI:SS",
    CASH_IN          ,
    CASH_OUT          ,
    NOTES_IN          ,
    CHANGE_OUT          ,
    WINNINGS          ,
    VTP               ,
    REFILL          ,
    TOKEN_IN          ,
    TOKEN_OUT          ,
    ELEC_PAY          ,
    ELEC_CREDIT          ,
    REMOTE_PAY          ,
    REMOTE_CREDIT     ,
    INSERT_TS      "TO_TIMESTAMP(SYSDATE, 'DD/MM/YYYY HH24:MI:SS')",
    FIFTY_PND          ,
    TWENTY_PND          ,
    TEN_PND          ,
    FIVE_PND          ,
    TWO_PND          ,
    ONE_PND          ,
    FIFTY_P          ,
    TWENTY_P          ,
    TEN_P          ,
    FIVE_P          
    all is good :o)

  • SQL Loader reads Data file Sequentially or Randomly?

    Will SQL Loader loads the data read from file Sequentially or Randomly?
    I have the data file like the below
    one
    two
    three
    four
    and my control file is
    LOAD DATA
    INFILE *
    TRUNCATE
    INTO TABLE T TRAILING NULLCOLS
    x RECNUM,
    y POSITION (1:4000)
    so my table will be polulated like
    X Y
    1 one
    2 Two
    3 Three
    4 Four
    Will this happend sequentially even for the large data sets? say i have from one to one million datas in my data files.
    Please clarify.
    Thanks,
    Rajesh.

    SQL Loader may read the file sequentially, but you should not rely on the physical ordering of the rows in the table.
    It looks like that's what you were hinting at.

  • Oracle 11G Direct SQL Load with Data Guard

    Does SQL Loader in direct mode always bypass the writing of redo logs ?
    If the database has force logging on, will SQL Loader in direct mode bypass the writing of redo logs ?
    Is there a way to run SQL Loader in direct mode that will create redo logs that can be applied by Data Guard to the backup database ?

    846797 wrote:
    Does SQL Loader in direct mode always bypass the writing of redo logs ?
    If the database has force logging on, will SQL Loader in direct mode bypass the writing of redo logs ?
    Is there a way to run SQL Loader in direct mode that will create redo logs that can be applied by Data Guard to the backup database ?In case of data guard setup , redo logs will always be generated.

  • How to filter some illegal rows when SQL Loader import data

    I want to import data in a csv file by SQL Loader.
    but , I don't want to import some illegal rows
    when the column 'name' is null
    how can I modify the SQL Loader ctrl file?

    Hi,
    refer this blogpost:
    http://gennick.com/allnull.html
    thanks,
    X A H E E R

  • SQL*LOADER and date formatted data

    Hi there, I don't want to load complex things in my table - just a simple date....
    The control file is:
    load data
    infile 'c:\data\mydata.csv'
    into table test_table
    fields terminated by "," optionally enclosed by '"'
    ( sampledate, name )
    The mydata.csv file is:
    30-12-2003, Test1
    31-12-2003, Test2
    However this format is not being accepted by the database... I tried other combinations of date (eg, 30122003, 20-DEC-2003, 30/12/2004, etc...) but always had a 'data error'
    Thanks for any suggestions.

    Example:
    Control File for Case Study 3
    This control file loads the same table as in case 2, but it loads three additional columns (hiredate, projno, and loadseq). The demonstration table emp does not have columns projno and loadseq. To test this control file, add these columns to the emp table with the command:
    ALTER TABLE emp ADD (projno NUMBER, loadseq NUMBER);
    The data is in a different format than in case 2. Some data is enclosed in quotation marks, some is set off by commas, and the values for deptno and projno are separated by a colon.
    1) -- Variable-length, delimited, and enclosed data format
    LOAD DATA
    2) INFILE *
    3) APPEND
    INTO TABLE emp
    4) FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY '"'
    (empno, ename, job, mgr,
    5) hiredate DATE(20) "DD-Month-YYYY",
    sal, comm, deptno CHAR TERMINATED BY ':',
    projno,
    6) loadseq SEQUENCE(MAX,1))
    7) BEGINDATA
    8) 7782, "Clark", "Manager", 7839, 09-June-1981, 2572.50,, 10:101
    7839, "King", "President", , 17-November-1981,5500.00,,10:102
    7934, "Miller", "Clerk", 7782, 23-January-1982, 920.00,, 10:102
    7566, "Jones", "Manager", 7839, 02-April-1981, 3123.75,, 20:101
    7499, "Allen", "Salesman", 7698, 20-February-1981, 1600.00,
    (same line continued) 300.00, 30:103
    7654, "Martin", "Salesman", 7698, 28-September-1981, 1312.50,
    (same line continued) 1400.00, 3:103
    7658, "Chan", "Analyst", 7566, 03-May-1982, 3450,, 20:101
    Joel Pèrez
    http://otn.oracle.com/experts

  • SQL Loader: Multiple data files to Multiple Tables

    How do you create one control file that refrences multiple data file and each file loads data in a different table.
    Eg.
    DataFile1 --> Table 1
    DataFile2 --> Table 2
    Contents and Structure of both data files are different. Data file is comma seperated.
    Below example is for 1 data file to 1 table. Need to modify this or create a wrapper that would call multiple control files.
    OPTIONS (SKIP=1)
    LOAD DATA
    INFILE DataFile1
    BADFILE DataFile1_bad.txt'
    DISCARDFILE DataFile1_dsc.txt'
    REPLACE
    INTO TABLE Table1
    FIELDS TERMINATED BY ","
    TRAILING NULLCOLS
    Col1,
    Col2,
    Col3,
    create_dttm sysdate,
    MySeq "myseq.nextval"
    Welcome any other suggestions.

    I was thinking if there is a way to indicate what file goes with what table (structure) in one control file.
    Example ( This does not work but wondering if something similar is allowed..)
    OPTIONS (SKIP=1)
    LOAD DATA
    INFILE DataFile1
    BADFILE DataFile1_bad.txt'
    DISCARDFILE DataFile1_dsc.txt'
    REPLACE
    INTO TABLE Table1
    FIELDS TERMINATED BY ","
    TRAILING NULLCOLS
    Col1,
    Col2,
    Col3,
    create_dttm sysdate,
    MySeq "myseq.nextval"
    INFILE DataFile2
    BADFILE DataFile2_bad.txt'
    DISCARDFILE DataFile2_dsc.txt'
    REPLACE
    INTO TABLE "T2"
    FIELDS TERMINATED BY ","
    TRAILING NULLCOLS
    T2Col1,
    T2Col2,
    T2Col3
    )

  • Can SQL*Loader Insert concatenated string into table

    Hi All,
    I want to insert a column, whose format is "abc" + to_char(sysdate,'YYYYMMDD'), into temp table. How can I do it? Thank you in advance.
    Best Regards,
    Sheng

    Hi Lukasz,
    Thank you for your help! The "abc" is a constant string, it isn't a column. And I use concat function to solve the problem. like this
    LOAD DATA
    INFILE data.txt
    INTO TABLE tmp_table
    fields terminated by "," optionally enclosed by '"'
    ( c1 "concat('abc',TO_CHAR(SYSDATE, 'YYYYMMDD'))"
    Sheng
    Edited by: Sheng on 2013-5-26 下午4:44

Maybe you are looking for

  • HELP me for Enemy Movement  !!!

    Hi guys, I've created Random movement for my enemies on a tilemap. Now I want that some enemies can "see" the player and therefore follow it. For this reason I make a straight line from my enemy to my player. The line can hits obstacles (blocked tile

  • HAL won't start after install on DL585 G2

    I ran a v40z for years and recently had SRSS 5.2 on S11 running just fine. This past week I replaced the v40z with a DL585 G2 and reinstalled S11 and SRSS 5.2. Everything went well except now HAL won't start failing with, I suspect, a timeout after s

  • How to call a function inside a class? 

    Hello, i am trying to fire a function onPress .. this function is inside a class. In this function i refer to another function inside the calss to call a Tween. It never arrives in the second function. I tried to make an example. In the fla file i ha

  • Bulkloader issue-javax.naming.NameNotFoundExce whilerunnng load_cm_data.cmd

    Hi I am trying to use bulk loader to load contents to repository. When i ran load_cm_data.cmd the following error is coming. Any idea what the reason could be. javax.naming.NameNotFoundException: While trying to lookup 'portalApp.BEA_conten t.Reposit

  • English Dictionary for 6300

    What's the maximum limit of java app for nokia 6300? My 6mb file of Oxford dictionary won't work.. [url=http://www.xanax2mg.com]buy xanax online[/url]