Could anyone tell me how to read 4 lines altogether and insert into table

Hi ,
I want to load the below data into table by using sql loader.
First 4 lines should insert in one single row in table and again it should from '01' load the next 4 lines in another row.
01suresh
02works
03in
04bankok
01kumar
02works
03in
04abudabi
01Raju
02works
03in
04france
Could you please give me some suggestion how i can accomplish it.
Thanks in advance.
Regards,
Vino

user1142030 wrote:
First 4 lines should insert in one single row in table and again it should from '01' load the next 4 lines in another row.Not a problem, use CONTINUEIF. Control file:
LOAD DATA
INFILE *
REPLACE
CONTINUEIF NEXT PRESERVE(1:2) != "01"
INTO TABLE continueif
TRAILING NULLCOLS
DUMMY FILLER POSITION(1:2),
COL1 TERMINATED BY '02',
COL2 TERMINATED BY '03',
COL3 TERMINATED BY '04',
COL4 TERMINATED BY '01'
BEGINDATA
01suresh
02works
03in
04bankok
01kumar
02works
03in
04abudabi
01Raju
02works
03in
04france Now:
SQL> create table continueif(
  2                          col1 varchar2(10),
  3                          col2 varchar2(10),
  4                          col3 varchar2(10),
  5                          col4 varchar2(10)
  6                         )
  7  /
Table created.
SQL> host sqlldr scott@orcl/tiger control=c:\temp\continueif.ctl log=c:\temp\continueif.log
SQL> select * from continueif
  2  /
COL1       COL2       COL3       COL4
suresh     works      in         bankok
kumar      works      in         abudabi
Raju       works      in         france
3 rows selected.
SQL> SY.

Similar Messages

  • Reg: read excel column and insert into table.

    hi Friends,
          i wanted to read the data from Excel and insert into in my oracle tables.
          can you provide the link or example script.
        how to read the column value from excel and insert into table.
      please help.

    < unnecessary reference to personal blog removed by moderator >
    Here are the steps:
    1) First create a directory and grant read , write , execute to the user from where you want to access the flat files and load it.
    2) Write a generic function to load PIPE delimited flat files:
    CREATE OR REPLACE FUNCTION TABLE_LOAD ( p_table in varchar2,
    p_dir in varchar2 DEFAULT ‘YOUR_DIRECTORY_NAME’,
    P_FILENAME in varchar2,
    p_ignore_headerlines IN INTEGER DEFAULT 1,
    p_delimiter in varchar2 default ‘|’,
    p_optional_enclosed in varchar2 default ‘”‘ )
    return number
    is
    – FUNCTION TABLE_LOAD
    – PURPOSE: Load the flat files i.e. only text files to Oracle
    – tables.
    – This is a generic function which can be used for
    – importing any text flat files to oracle database.
    – PARAMETERS:
    – P_TABLE
    – Pass name of the table for which import has to be done.
    – P_DIR
    – Name of the directory where the file is been placed.
    – Note: The grant has to be given for the user to the directory
    – before executing the function
    – P_FILENAME
    – The name of the flat file(a text file)
    – P_IGNORE_HEADERLINES
    – By default we are passing 1 to skip the first line of the file
    – which are headers on the Flat files.
    – P_DELIMITER
    – Dafault “|” pipe is been passed.
    – P_OPTIONAL_ENCLOSED
    – Optionally enclosed by ‘ ” ‘ are been ignored.
    – AUTHOR:
    – Slobaray
    l_input utl_file.file_type;
    l_theCursor integer default dbms_sql.open_cursor;
    l_lastLine varchar2(4000);
    l_cnames varchar2(4000);
    l_bindvars varchar2(4000);
    l_status integer;
    l_cnt number default 0;
    l_rowCount number default 0;
    l_sep char(1) default NULL;
    L_ERRMSG varchar2(4000);
    V_EOF BOOLEAN := false;
    begin
    l_cnt := 1;
    for TAB_COLUMNS in (
    select column_name, data_type from user_tab_columns where table_name=p_table order by column_id
    ) loop
    l_cnames := l_cnames || tab_columns.column_name || ‘,’;
    l_bindvars := l_bindvars || case when tab_columns.data_type in (‘DATE’, ‘TIMESTAMP(6)’) then ‘to_date(:b’ || l_cnt || ‘,”YYYY-MM-DD HH24:MI:SS”),’ else ‘:b’|| l_cnt || ‘,’ end;
    l_cnt := l_cnt + 1;
    end loop;
    l_cnames := rtrim(l_cnames,’,');
    L_BINDVARS := RTRIM(L_BINDVARS,’,');
    L_INPUT := UTL_FILE.FOPEN( P_DIR, P_FILENAME, ‘r’ );
    IF p_ignore_headerlines > 0
    THEN
    BEGIN
    FOR i IN 1 .. p_ignore_headerlines
    LOOP
    UTL_FILE.get_line(l_input, l_lastLine);
    END LOOP;
    EXCEPTION
    WHEN NO_DATA_FOUND
    THEN
    v_eof := TRUE;
    end;
    END IF;
    if not v_eof then
    dbms_sql.parse( l_theCursor, ‘insert into ‘ || p_table || ‘(‘ || l_cnames || ‘) values (‘ || l_bindvars || ‘)’, dbms_sql.native );
    loop
    begin
    utl_file.get_line( l_input, l_lastLine );
    exception
    when NO_DATA_FOUND then
    exit;
    end;
    if length(l_lastLine) > 0 then
    for i in 1 .. l_cnt-1
    LOOP
    dbms_sql.bind_variable( l_theCursor, ‘:b’||i,
    ltrim(rtrim(rtrim(
    regexp_substr(l_lastLine,’([^|]*)(\||$)’,1,i),p_delimiter),p_optional_enclosed),p_optional_enclosed));
    end loop;
    begin
    l_status := dbms_sql.execute(l_theCursor);
    l_rowCount := l_rowCount + 1;
    exception
    when OTHERS then
    L_ERRMSG := SQLERRM;
    insert into BADLOG ( TABLE_NAME, ERRM, data, ERROR_DATE )
    values ( P_TABLE,l_errmsg, l_lastLine ,systimestamp );
    end;
    end if;
    end loop;
    dbms_sql.close_cursor(l_theCursor);
    utl_file.fclose( l_input );
    commit;
    end if;
    insert into IMPORT_HIST (FILENAME,TABLE_NAME,NUM_OF_REC,IMPORT_DATE)
    values ( P_FILENAME, P_TABLE,l_rowCount,sysdate );
    UTL_FILE.FRENAME(
    P_DIR,
    P_FILENAME,
    P_DIR,
    REPLACE(P_FILENAME,
    ‘.txt’,
    ‘_’ || TO_CHAR(SYSDATE, ‘DD_MON_RRRR_HH24_MI_SS_AM’) || ‘.txt’
    commit;
    RETURN L_ROWCOUNT;
    end TABLE_LOAD;
    Note: when you run the function then it will also modify the source flat file with timestamp , so that we can have the track like which file was loaded .
    3) Check if the user is having UTL_FILE privileges or not :
    SQL> SELECT OWNER,
    OBJECT_TYPE
    FROM ALL_OBJECTS
    WHERE OBJECT_NAME = ‘UTL_FILE’
    AND OWNER =<>;
    If the user is not having the privileges then grant “UTL_FILE” to user from SYS user:
    SQL> GRANT EXECUTE ON UTL_FILE TO <>;
    4) In the function I have used two tables like:
    import_hist table and badlog table to track the history of the load and another to check the bad log if it occurs while doing the load .
    Under the same user create an error log table to log the error out records while doing the import:
    SQL> CREATE TABLE badlog
    errm VARCHAR2(4000),
    data VARCHAR2(4000) ,
    error_date TIMESTAMP
    Under the same user create Load history table to log the details of the file and tables that are imported with a track of records loaded:
    SQL> create table IMPORT_HIST
    FILENAME varchar2(200),
    TABLE_NAME varchar2(200),
    NUM_OF_REC number,
    IMPORT_DATE DATE
    5) Finally run the PLSQL block and check if it is loading properly or not if not then check the badlog:
    Execute the PLSQL block to import the data from the USER:
    SQL> declare
    P_TABLE varchar2(200):=<>;
    P_DIR varchar2(200):=<>;
    P_FILENAME VARCHAR2(200):=<>;
    v_Return NUMBER;
    BEGIN
    v_Return := TABLE_LOAD(
    P_TABLE => P_TABLE,
    P_DIR => P_DIR,
    P_FILENAME => P_FILENAME,
    P_IGNORE_HEADERLINES => P_IGNORE_HEADERLINES,
    P_DELIMITER => P_DELIMITER,
    P_OPTIONAL_ENCLOSED => P_OPTIONAL_ENCLOSED
    DBMS_OUTPUT.PUT_LINE(‘v_Return = ‘ || v_Return);
    end;
    6) Once the PLSQL block is been executed then check for any error log table and also the target table if the records are been successfully imported or not.

  • How to read ecel sheet and insert into oracle table

    hi all,
    am working on forms builder 6i. and i want , from a trigger to read from a a sheet excel file the data and insert into a table that i had aleady created.
    i whrite a code that can till now open the excel file but i cant read the data to insert it into the table.
    am using TEXT_IO.IS_OPEN to open the file
    TEXT_IO.GET_LINE to take each line
    and subst(x as variable) to read the first line , but the subsrt return nohing
    any solution??

    There's already a topic made on this: how to copy data from excel to oracle forms

  • Could anyone tell me how many discs are suppose to come in this 10.4 Tiger Box?

    Could anyone tell me how many discs are suppose to come in this 10.4 Tiger Box? I might have bought more than one box at one time and then just combined the discs. I have two black OS X discs that look almost identical with the exception of what looks one disk is 10.4 and the other is 10.4.6.

    One DVD or four CDs depending on what you purchased.
    (67080)

  • Hi, could anyone tell me how can I access and old Apple ID account?

    Hi could anyone tell me how to access an old Apple account, I cannot remember either the original email or password.?

    You can use "iForgot" here >  Apple - My Apple ID
    Frequently Asked Questions About Apple ID

  • HT5639 I have ordered a macbook pro retina 13 with English (US) keyboard. Please could anyone tell me how to change it to an English+arabic layout keyboard?

    I have ordered a macbook pro retina 13 with English (US) keyboard. Please could anyone tell me how to change it to an English+arabic layout keyboard?
    I can order an English+Arabic layout mac keyboard, but I do not where can I go asking for this change?
    I found another solution to change the keys of keyboard one by one, but I dont want to do it myself. I may destroy it. Any solution?

    Cancel your order and re-order one with the desired KB

  • Can anyone tell me how to setup odbc driver and configure in the setup

    Can anyone tell me how to setup odbc driver and configure in the setup

    You can't switch languages in OS X programs, just in the OS itself. Insert the Leopard OS X disc, and choose your new preferred language when prompted.

  • HT1391 Hi can anyone tell me how to find out what and when my last purchases were made from the App Store ? I think my kids used all my credit

    Hi can anyone tell me how to find out what and when my last purchases were made from the App Store ? I think my kids used all my credit

    .from iTunes, go to View > Show sidebar
    From sidebar > Itunes Store > Click top left on your Apple ID email address > Account > ...scroll down > Purchase History > View All

  • Hi, I have accidently delete a keynote app, could someone tell me how to redownload the app and retrieve all the contained information

    Hi, I have accidently delete a keynote app, could someone tell me how to redownload the app and retrieve all the contained information? Thank you!

    You are most welcome

  • Could anyone tell me how too change the mouse cursor to the waiting mode?

    Could please anyone tell me how too change the mouse cursor to the waiting mode while my applet is processing?
    Well i have 3 combos in my applet.....and in my actionPerformed code i have:
    public void actionPerformed(ActionEvent e) {
    if (e.getSource() == combo1) {
              setCursor (Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    ind_reg = combo1.getSelectedIndex();
    Do_Accion1();
    setCursor (Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
    if (e.getSource() == combo2) {
    setCursor (Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    ind_mun = combo2.getSelectedIndex();
    Do_Accion2();
    setCursor (Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
    if (e.getSource() == combo3) {
    setCursor (Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    ind_loc = combo3.getSelectedIndex();
    Do_Accion3();
    setCursor (Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
    } // Fin action event
    But my cursor is never change to WAIT_CURSOR....Somebody could help me please?....
    Thanks in advance....
    Mary

    YourComponent.setCursor(
         Cursor.getPredefinedCursor(
         Cursor.WAIT_CURSOR));

  • Excute, me could anyone tell me how to know wether iphone 4s is original or fake?

    Excute me, everyone could you tell me how to check wether the iphone 4s is original or fake..?

    What makes you think it's a fake, where did you purchase it from? If you have access to the iPhone, check the serial number using both these links http://www.chipmunk.nl/klantenservice/applemodel.html / https://selfsolve.apple.com/agreementWarrantyDynamic.do

  • Can anyone tell me how to read a crash report?

    I can not find anywhere on how to read a crash report. Can anyone tell me? The only tutorial I have found is located here, but it pay-for subscription only.
    For some reason I a lot of my applications are crashing. A lot of the applications are 3rd party, but today two Apple applications crashed...Preview and iPhoto.
    The only thing I can attribute to these crashes is my uninstallation of Garage Band using Deinstaller. I uninstalled all GarageBand*.pkg files in my /Library/Receipts/ folder.
    Here are my two recent crash reports: iPhoto Preview
    Any help would be much appreciated!

    I used Pacifist to replace what the Product
    Specialist was the corrupt file and I am still
    crashing applications...specifically BLT. Click here to view crash report. I have
    never had a problem with BLT, so I don't know why its
    just now starting to crash.
    I redownloaded the
    application and have notified the Developer
    requesting assistance. I think it's a system issue
    because it happens in multiple user
    accounts.
    The crash report refers
    consistently to 0x9294d120 which is at the top of the
    crashed thread. This thread refers to a
    com.apple.Foundation file causing the
    problem. I can not locate this file anywhere
    within my system or the 10.4.6 Combo
    update.....anyone have any suggestions after
    reviewing the crash report?
    Here is a technical guide concerning the Crash Report:
    http://developer.apple.com/technotes/tn2004/tn2123.html
    and here is a guide for Crash reporting:
    http://developer.apple.com/bugreporter/bugreportingguide.html
    Apple, of course doesn't have to support third-party products, so it's best to contact the third party with regards the issue. There are simple things you can check like the installation, hardware incompatibilities... etc, but I assume you have done this from reading the earlier verbiage in the thread.

  • How to read XML file and write into another XML file

    Hi all, I am new to JAVAXML.
    My problem is I have to read one XML file and take some Nodes from that and write these nodes into another XML file...
    I solved, how to read XML file
    But I don't know how to Write nodes into another XML.
    Can anyone help in this???
    Thanks in advance..

    This was answered a bit ago. There was a thread called "XML Mergine" that started on Sept 14th. It has a lot of information about what it takes to copy nodes from one XML Document object into another.
    Dave Patterson

  • Read text file and insert into MySQL

    Dears,
    I need to read text file and then insert the data in the correct column in the MySQL database
    example
    I have the following text file:
    field1=1234 field2=56789 field3=444555
    field1=1333 field2=2222 field3=333555
    and so on and so forth ,,note that all rows are identical and just the filed value is changed(there is a dilemeter between fields)
    how can I read field1,field2 and field3 from text file and insert them in the correct table and column in the database.....
    any help?????
    thanks for your cooperation
    Best Regars

    Sure.
    Which part don't you understand?
    1. Reading a text file
    2. Parsing the text file contents.
    3. Relational databases and SQL.
    4. How to create a database.
    5. How to connect to a database in Java.
    6. How to insert records into the database in Java.
    7. How to map Java objects to records in a database.
    This is a pretty nice list. Solve complex problems by breaking them into smaller ones.
    %

  • Hello..could anyone tell me how to fix the wireless connection that turned grayed permanently on my iphone4s

     

    You could just select "forget this network"
    You can do settings-general-reset-reset network settings
    reset network settings will reset to default any wifi info, passwords etc.

Maybe you are looking for