SQL LOADER - How to combine 3 rows into 1

Hi,
I have an input file composed of 4 different data types in 4 rows.
line1 has fld1 text(100)
line2 has fld2 number(4)
line3 has fld3 date(10) "mm/dd/yyyy"
line4 has fld4 date(10) "mm/dd/yyyy"
all line has data in it.
This is my control file:
LOAD DATA
INFILE "fileA.txt"
truncate
CONCATENATE 4
INTO TABLE ps_vz_ppc_blng_aud
TRAILING NULLCOLS
( text_fld CHAR(100) TERMINATED BY WHITESPACE
,num_fld INTEGER EXTERNAL(4)
TERMINATED BY WHITESPACE
,begin_date DATE(10) "mm/dd/yyyy"
TERMINATED BY WHITESPACE
,end_date DATE(10) "mm/dd/yyyy"
TERMINATED BY WHITESPACE
,row_added_dttm     sysdate
,row_added_oprid "USER"
My error: cannot insert null into num_fld.
What did I do wrong? Terminated by whitespace did not end when the line end? Or the first field needs to be 100 characters and ends with end of line?

That means the structure of your data is now something like:
line1|1|01/01/2001|02/01/2001
line2|2|01/01/2002|02/01/2002If so, you can use the following control file
LOAD DATA
INFILE "fileA.txt"
truncate
INTO TABLE ps_vz_ppc_blng_aud
FIELDS TERMINATED BY "|" OPTIONALLY ENCLOSED BY '"'
( text_fld        char
, num_fld         integer external
, begin_date      DATE "mm/dd/yyyy"
, end_date        DATE "mm/dd/yyyy"
, row_added_dttm  sysdate
, row_added_oprid EXPRESSION "USER"
)P.S. There is no automatic notification, just come back from time to time and check for new postings.

Similar Messages

  • SQL*Loader - How to combine Flat File 3 columns and put into one single column

    Receive a flat file delimited by comma. Want to combine Flat File last 3 columns and put into one single column(Table).
    e.g.
    Flat File
    100,239,30,20,30
    While inserting into table want to combine last 3 columns and insert into invoice number column.
    302030

    It is not possible to combine the last 3 columns as those columns are seperated by commas and in the SQL Loader control file you must ve specified COMMA as an delimiter. So u better have all the columns in the table plus add one more column which holds the concatenation of the 3 columns.
    Vijay

  • SQL*Loader - How to combine 2 controlfiles to one controlfile

    I have several controllfiles which each import another table from another datafile, because I don't want execute every seperat or create a batch file.... I'm looking for a way to put they all in one single controlfile.
    example:
    1st ctl-file:
    LOAD DATA
    INFILE "t1.dat"
    INTO TABLE t1 REPLACE
    FIELDS TERMINATED BY "     "
    (c1,
    c2 "to_number(:c2,'99999999999999999.99999999999999999','NLS_NUMERIC_CHARACTERS=''.,''')",
    c3 date 'YYYY-MM-DD"T"HH24:MI:SS')
    gQuqT     478.60636734965914     2006-12-05T11:00:49
    ÜgQK     963.0277916962095     2006-12-30T08:03:00
    üZfxN     465.15226622488257     2006-12-30T09:14:12
    2nd ctl-file:
    LOAD DATA
    INFILE "t2.dat"
    INTO TABLE t2 REPLACE
    FIELDS TERMINATED BY "     "
    (c1,
    c2 "to_number(:c2,'99999999999999999.99999999999999999','NLS_NUMERIC_CHARACTERS=''.,''')")
    alvwxs     13.0
    poeh     15.0
    zpgiht     21.0
    At the examples is everytime used a id column, to ident which row should import in which table.
    But at my case i need something like a where condition from which file the data should be imported....how should it look?
    Can someone give me an advice how a controlfile should look which import both tables in one controlfile?
    BR
    roland

    It is not possible to combine the last 3 columns as those columns are seperated by commas and in the SQL Loader control file you must ve specified COMMA as an delimiter. So u better have all the columns in the table plus add one more column which holds the concatenation of the 3 columns.
    Vijay

  • Sql loader, how to get decimals into the database?

    oracle 10.2
    we have data of the form
    1.10
    1.11
    we are using "decimal external" in the control file.
    The table is a straight number field
    I did a test where I created a table with a number field and without and precision and did regular inserts. I got the decimal values.
    so I did
    create table x (y number);
    insert into x values (1.10);
    insert into x values (1.11);
    and i got back
    1.1
    1.11
    when we sql load we get
    1
    1

    Why use decimal external then? What's wrong with leaving the field as number?

  • How to convert rows into column

    Hi,
    can any one help me how to convert rows into column by pl/sql procedure.
    Thanks and Regards

    http://www.oracle.com/technology/oramag/code/tips2004/050304.html
    -- dropping the sample table if exists
    drop table rowstocol
    -- create sample table
    create table rowstocol ( name varchar2(20));
    -- Inserting rows into sample table
    insert into rowstocol values('Amit Zhankar');
    insert into rowstocol values('Piyu Yawalkar');
    insert into rowstocol values('Piyu Yawalkar');
    insert into rowstocol values('Ashish Ghelani');
    insert into rowstocol values('Aditi Zhankar');
    insert into rowstocol values('Tom Kyte');
    insert into rowstocol values('Oracle');
    -- Following query should be run to create a sql. This result sql should be run to convert rows to column.
    -- The following query uses just the tablename (whose data is to be converted) and name of the column (which is to be converted).
    -- Example taken here is table rowstocol, column name.
    SELECT cc
    FROM (select decode(rn ,1 ,'Select ',null) ||' MAX (CASE WHEN dr = '|| rownum||' THEN DECODE (rn,1, col1) END) '||
    decode(rn,maxr,' col1 from ','||'||chr(39)||','||chr(39)||'|| ') cc,rn,maxr
    from (SELECT ROWNUM rn,count(0) over() maxr FROM rowstocol) order by rn) trows
    union all
    select '(SELECT tabs.col1, DENSE_RANK () OVER (ORDER BY col1,rowid) dr,dense_rank() OVER (order by 1) rn
    FROM (SELECT NAME col1 FROM rowstocol) tabs ) group by rn' cc from dual;
    -- The result of this query will do the reqd conversion from row to column.
    -- Replace table rowstocol by your table, column name by your column.
    CC
    Select MAX (CASE WHEN dr = 1 THEN DECODE (rn,1, col1) END) ||','||
    MAX (CASE WHEN dr = 2 THEN DECODE (rn,1, col1) END) ||','||
    MAX (CASE WHEN dr = 3 THEN DECODE (rn,1, col1) END) ||','||
    MAX (CASE WHEN dr = 4 THEN DECODE (rn,1, col1) END) ||','||
    MAX (CASE WHEN dr = 5 THEN DECODE (rn,1, col1) END) ||','||
    MAX (CASE WHEN dr = 6 THEN DECODE (rn,1, col1) END) ||','||
    MAX (CASE WHEN dr = 7 THEN DECODE (rn,1, col1) END) ||','||
    MAX (CASE WHEN dr = 8 THEN DECODE (rn,1, col1) END) col1 from
    (SELECT tabs.col1, DENSE_RANK () OVER (ORDER BY col1,rowid) dr,dense_rank() OVER (order by 1) rn
    FROM (SELECT NAME col1 FROM rowstocol) tabs ) group by rn
    Select MAX (CASE WHEN dr = 1 THEN DECODE (rn,1, col1) END) ||','||
    MAX (CASE WHEN dr = 2 THEN DECODE (rn,1, col1) END) ||','||
    MAX (CASE WHEN dr = 3 THEN DECODE (rn,1, col1) END) ||','||
    MAX (CASE WHEN dr = 4 THEN DECODE (rn,1, col1) END) ||','||
    MAX (CASE WHEN dr = 5 THEN DECODE (rn,1, col1) END) ||','||
    MAX (CASE WHEN dr = 6 THEN DECODE (rn,1, col1) END) ||','||
    MAX (CASE WHEN dr = 7 THEN DECODE (rn,1, col1) END) ||','||
    MAX (CASE WHEN dr = 8 THEN DECODE (rn,1, col1) END) col1 from
    (SELECT tabs.col1, DENSE_RANK () OVER (ORDER BY col1,rowid) dr,dense_rank() OVER (order by 1) rn
    FROM (SELECT NAME col1 FROM rowstocol) tabs ) group by rn;
    COL1
    Aditi Zhankar,Amit Zhankar,Ashish Ghelani,Oracle,Oracle,Piyu Yawalkar,Piyu Yawalkar,Tom Kyte
    Edited by: bhooma on Jan 20, 2009 2:44 AM

  • How to convert rows into columns with decode function

    Hi,
    How to convert rows into columns with the help of decode function in oracle.
    thanks and regards
    P Prakash

    say
    col1 col2
    1 10
    2 20
    3 30
    then use
    select col1,
    sum(decode(col2,10,10)) "new1"
    sum(decode(col2,20,20))"new2"
    sum(decode(col2,30,30))"new3"
    from table_name
    group by col1;
    we used sum u can use ny function if wont u have to give the column name i.e col2 name also
    so i think u got it nw
    regards

  • How to convert rows into columns

    Hi,
    How to convert rows into columns of two different tables.
    These two tables have two common columns namely (shipline,pos).
    Let me know if we have any built in functions to do this.
    thank you very much .
    Edited by: 808542 on Dec 7, 2010 8:35 PM
    Edited by: 808542 on Dec 7, 2010 8:37 PM

    Have you tried this first?
    http://forums.oracle.com/forums/search.jspa?threadID=&q=row+to+column&objID=f75&dateRange=last90days&userID=&numResults=15&rankBy=10001

  • Sql loader how import a file with save the actual row number in a db field

    Hey,
    how can i save the row number for each row in a file into a database field i the same table with the sql loader (sqlldr)?
    test data:
    john doe
    joe meier
    table:
    name surname line_number_in_file
    john doe 1
    joe meier 2
    and so on ... an if an line is discarded because it is empty for example it should be as this:
    test data:
    john doe
    joe meier
    table:
    name surname line_number_in_file
    john doe 1
    joe meier 3
    thanks for helpinmg and excuse my very bad english :-)
    Message was edited by:
    user527827

    but if one of the when clause faild or some rows are
    rejectet the sequence is not right.Did you read the link?
    "If a record is rejected (that is, it has a format error or causes an Oracle error), the generated sequence numbers are not reshuffled to mask this. If four rows are assigned sequence numbers 10, 12, 14, and 16 in a particular column, and the row with 12 is rejected, the three rows inserted are numbered 10, 14, and 16, not 10, 12, and 14. This allows the sequence of inserts to be preserved despite data errors. When you correct the rejected data and reinsert it, you can manually set the columns to agree with the sequence."
    also if you read multiple lines and they inserted in
    the wrong order the number from the sequence is not
    the line number...what do you mean with "reading multiple lines and wrong order?"

  • SQL Loader-How to insert -ve & date values from flat text file into coloumn

    Question: How to insert -ve & date values from flat text file into coloumns in a table.
    Explanation: In the text file, the negative values are like -10201.30 or 15317.10- and the date values are as DDMMYYYY (like 10052001 for 10th May, 2002).
    How to load such values in columns of database using SQL Loader?
    Please guide.

    Question: How to insert -ve & date values from flat text file into coloumns in a table.
    Explanation: In the text file, the negative values are like -10201.30 or 15317.10- and the date values are as DDMMYYYY (like 10052001 for 10th May, 2002).
    How to load such values in columns of database using SQL Loader?
    Please guide. Try something like
    someDate    DATE 'DDMMYYYY'
    someNumber1      "TO_NUMBER ('s99999999.00')"
    someNumber2      "TO_NUMBER ('99999999.00s')"Good luck,
    Eric Kamradt

  • How to combine rows with small numbers into single "other" row?

    How can I combine rows with value 6(for example) or lower to single row representing the SUM of all this values and label OTHER, so the pie chart will have a chance to display all small values combined?
    I'm using Numbers 09

    HI Peter,
    When you write a decimal number, is the decimal separator a period ( . ) or a comma ( , )? If it's a comma, then the syntax error can be corrected by replacing the list separator in the formula, a comma in Jerry's formula, with a semi colon ( ; ):
    =SUMIF(B; "<6"; B)
    (Added): The two Bs appear in blue 'lozenges' in Jerry's image because that is the way cell (or column) references are displayed in Numbers when a formula has correct syntax.
    Regards,
    Barry
    Message was edited by: Barry

  • SQL Loader (how to cut data header)

    Hi there,
    [oracle 11g]
    I got the following text file:
    mod; DD.MM.YYYY; HH:MM:SS; aligned
    src; "ptv "; "15.04.2012"; "10:47:49"
    chs; "ISO8859-1"
    ver; "V1.0"
    ifv; "V1.0"
    dve; "V1.0"
    fft; "LIO"
    tbl; MENGE_FGR
    atr; BASIS_VERSION; FGR_NR; FGR_TEXT
    frm; num[9.0]; num[5.0]; char[40]
    rec;        122;     8; "VVZ"   
    rec;        123;     18; "VHZ"
    rec;        124;     13; "VTZ"    Now I am interested in the column TBL and ATR and follwing rawdata
    Do you see a way to automatically create the table MENGE_FR with columns BASIS_VERSION; FGR_NR;FGR_TEST and column types num, num, char and insert the raw data below?
    PS:OK, this is mysql ...so I need to convert this first to sql. So you should see num as number.
    Thx in advance Thorsten
    Edited by: Thorsten on 16.05.2013 07:30
    Edited by: Thorsten on 16.05.2013 07:32

    There are various ways that you could do this. I have demonstrated one method below. I created a table with two columns, then used SQL*Loader to load the data from the text file into those two columns. Skipping the header rows is optional. You could also use an external table instead, if the text file is on your server, not your client. I then used some PL/SQL to create and execute "create table" and "insert" statements. This is just some starter code. You will need to make modifications to handle other data types and such that were not in the example that you provided, but it should give you the general idea.
    SCOTT@orcl_11gR2> host type text_file.dat
    mod; DD.MM.YYYY; HH:MM:SS; aligned
    src; "ptv "; "15.04.2012"; "10:47:49"
    chs; "ISO8859-1"
    ver; "V1.0"
    ifv; "V1.0"
    dve; "V1.0"
    fft; "LIO"
    tbl; MENGE_FGR
    atr; BASIS_VERSION; FGR_NR; FGR_TEXT
    frm; num[9.0]; num[5.0]; char[40]
    rec;        122;     8; "VVZ"
    rec;        123;     18; "VHZ"
    rec;        124;     13; "VTZ"
    SCOTT@orcl_11gR2> host type test.ctl
    options(skip=7)
    load data
    infile text_file.dat
    into table tbl
    (col1 terminated by ';',
    col2 terminated by x'0a')
    SCOTT@orcl_11gR2> create table tbl
      2    (col1  varchar2(4),
      3     col2  varchar2(60))
      4  /
    Table created.
    SCOTT@orcl_11gR2> host sqlldr scott/tiger control=test.ctl log=test.log
    SQL*Loader: Release 11.2.0.1.0 - Production on Thu May 16 13:44:24 2013
    Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
    Commit point reached - logical record count 6
    SCOTT@orcl_11gR2> select * from tbl
      2  /
    COL1 COL2
    tbl   MENGE_FGR
    atr   BASIS_VERSION; FGR_NR; FGR_TEXT
    frm   num[9.0]; num[5.0]; char[40]
    rec          122;     8; "VVZ"
    rec          123;     18; "VHZ"
    rec          124;     13; "VTZ"
    6 rows selected.
    SCOTT@orcl_11gR2> declare
      2    v_tab   varchar2(30);
      3    v_atr   varchar2(32767);
      4    v_frm   varchar2(32767);
      5    v_sql   varchar2(32767);
      6    v_cols  number;
      7    v_next  varchar2(32767);
      8  begin
      9    select col2 into v_tab from tbl where col1 = 'tbl';
    10    select col2 || ';' into v_atr from tbl where col1 = 'atr';
    11    select col2 || ';' into v_frm from tbl where col1 = 'frm';
    12    v_sql := 'CREATE TABLE ' || v_tab || ' (';
    13    select regexp_count (col2, ';') + 1 into v_cols from tbl where col1 = 'atr';
    14    for i in 1 .. v_cols loop
    15      v_sql := v_sql || substr (v_atr, 1, instr (v_atr, ';') - 1) || ' ';
    16      v_next := substr (v_frm, 1, instr (v_frm, ';') - 1);
    17      v_next := replace (v_next, '[', '(');
    18      v_next := replace (v_next, ']', ')');
    19      v_next := replace (v_next, '.', ',');
    20      v_next := replace (v_next, 'num', 'number');
    21      v_next := replace (v_next, 'char', 'varchar2');
    22      v_sql := v_sql || v_next || ',';
    23      v_atr := substr (v_atr, instr (v_atr, ';') + 1);
    24      v_frm := substr (v_frm, instr (v_frm, ';') + 1);
    25    end loop;
    26    v_sql := rtrim (v_sql, ',') || ')';
    27    dbms_output.put_line (v_sql);
    28    execute immediate v_sql;
    29    for r in (select col2 from tbl where col1 = 'rec') loop
    30      v_sql := 'INSERT INTO ' || v_tab || ' VALUES (''';
    31      v_sql := v_sql || replace (replace (r.col2, ';', ''','''), '"', '');
    32      v_sql := v_sql || ''')';
    33      dbms_output.put_line (v_sql);
    34      execute immediate v_sql;
    35    end loop;
    36  end;
    37  /
    CREATE TABLE  MENGE_FGR ( BASIS_VERSION  number(9,0), FGR_NR  number(5,0),
    FGR_TEXT  varchar2(40))
    INSERT INTO  MENGE_FGR VALUES ('        122','     8',' VVZ')
    INSERT INTO  MENGE_FGR VALUES ('        123','     18',' VHZ')
    INSERT INTO  MENGE_FGR VALUES ('        124','     13',' VTZ')
    PL/SQL procedure successfully completed.
    SCOTT@orcl_11gR2> describe menge_fgr
    Name                                      Null?    Type
    BASIS_VERSION                                      NUMBER(9)
    FGR_NR                                             NUMBER(5)
    FGR_TEXT                                           VARCHAR2(40)
    SCOTT@orcl_11gR2> select * from menge_fgr
      2  /
    BASIS_VERSION     FGR_NR FGR_TEXT
              122          8  VVZ
              123         18  VHZ
              124         13  VTZ
    3 rows selected.

  • SQL*Loader: How to load multi-line report data?

    Hi,
    is it possible to use SQL*Loader to load data from a hierarchical structured fixed column ASCII file like this
    001 scott
    New York 01.01.2002 1234
    Chicago 15.10.2001 9876
    002 smith
    Los Angeles 24.12.1999 5678
    Washington 01.12.1999 0000
    Chicago 01.01.2000 1111
    into one database table:
    id name city day code
    001 scott New York 01.01.2002 1234
    001 scott Chicago 15.10.2001 9876
    002 smith Los Angeles 24.12.1999 5678
    002 smith Washington 01.12.1999 0000
    002 smith Chicago 01.01.2000 1111
    The number of lines per name is unlimited, the next line starts after a separating ---- line.
    We cannot change the format of the text file to import.
    There is an example in the documentation that shows how to load a structure like the following via insert triggers:
    001 scott New York 01.01.2002 1234
    Chicago 15.10.2001 9876
    002 smith Los Angeles 24.12.1999 5678
    Washington 01.12.1999 0000
    Chicago 01.01.2000 1111
    But we have the name information on a separate header line, so I don't know if we can use a similar technique here.
    regards
    Sven

    Try enclosing your strings with e.g. a double-quote. To do so, the control file needs the following (example):
    LOAD DATA
    REPLACE
    INTO TABLE test          
    FIELDS TERMINATED BY '|' OPTIONALLY ENCLOSED BY '"'
    TRAILING NULLCOLS
    id1,
    id2,
    id3,
    id4,
    )of course this does mean that your data must change...
    L.

  • SQL*LOADER how to load blanks when data is null

    I need to load data which contains null values into a table which cannot contains nulls. How can I tell SQL*LOADER to load blanks in a column when the input data is nulls?

    I think something like this in your control file should work:
    col1 char(10) nvl(col1,' ')

  • SQL*Loader - How to load only a few columns from a .csv file to ora table

    Hi there,
    Could anyone please let me know how to load few columns from a .csv
    file into a oracle table using SQL*Loader.
    I know how to create a .dat and .ctl file and run the sql loader.
    Suppose I have a .csv file with
    col1, col2, col3, col4
    and I only need to load col1 and col3 into col_a and col_b respectively
    in table_a?
    structure of table_ a
    col_a,
    col_b
    Please advice

    Try like..it i will work..
    LOAD DATA
    INFILE 'test.txt'
    LOAD DATA
    TRUNCATE INTO TABLE T1
    FIELDS TERMINATED BY ','
    (col1,
    col2 FILLER,
    col3,
    col4 FILLER
    )

  • SQL*Loader-350: Illegal combination of non-alphanumeric characters

    Hi all,
    how to skip a column in control file.
    i.e.
    I have a table with 10 columns and FAT file contains 11 columns.
    how to skip a last column ?
    and
    I added extra column to Table and I changed the control file too.
    but i am getting error.
    SQL*Loader-350: Syntax error at line 115.
    Illegal combination of non-alphanumeric characters
    thanks in Advance.

    Tom Kyte has an elaborate solution on his page:
    http://osi.oracle.com/~tkyte/SkipCols/index.html
    Or post the table description and the control file, so we can have a look at it.

Maybe you are looking for

  • After I open FireFax 4 to my home page and then try to navigate elsewhere, I do not have access to the back arrow to return to the home page. What setting is causing this to happen?

    Toshiba Satellite Laptop Vista Home Premium Firefox 4.0 recently installed Every time I load Firefox, my home page comes up. After going to another page, I do not see the back arrow highlighted, and the only way to get to the home page, I have to cli

  • Downloaded files from safari

    my program upgrade files downloaded appear damaged. I have downloaded from adobe and other sites, get warning that downloaded files are damaged and need to move to trash. Mac pro 3.7GHz late 2013 with 10.10.1 and 12 GB ram

  • Dreamweaver and Photoshop

    I am really frustrated! I built a website in photoshop, added some forms in dreamweaver and have a header done in flash. In dreamweaver, my forms are placed higher then they should be on the page covering other text. My flash header won't even load a

  • RPC-XML and JMXBeans works behind a firewall?

    Hi, i�m studing Java and have a question, RPC-XML and JMXBeans is possible to run this tecnologies in Internet?? for example, if i have a J2EE server or a RPC-XML server and it is public for Internet, somebody can access to my services from his offic

  • WRT54G issue

    Hello. First time posting here and I know next to nothing when it comes to routers and stuff, so sorry if this has been asked before. We have a WRT54G router from probably around 2005. Our ISP is KMTelecom (a local one, and we're about as far away fr