CSV FILE LOADING TABLE

I HAVE A CSV FILE in a D:\ in car THAT HAVE 3 FIELDS.
1st is digital and 2 others are alphabatic
For example...

no name Name_ father

1 sajid ahmed
2 chuck jhon


ALSE I hava a table in the database.

Create table test (id number, name varchar2 (50), fname varchar2 (50));

my code is


PROCEDURE get_city_data
IS

file_handle text_io.file_type;
seperator VARCHAR2 (1): = ', ';
city_row VARCHAR2 (32767).
skip_first_row BOOLEAN: = TRUE; -skip the first line because it has the fields name


NUMBER OF V_ID;
V_NAME VARCHAR2 (50);
V_FNAME VARCHAR2 (50);




BEGIN


file_handle: = text_io.fopen (would be: \book1.csv', 'R');

BEGIN

LOOP
TEXT_IO.get_line (file_handle, city_row);
IF skip_first_row
THEN
skip_first_row: = FALSE;
ON THE OTHER

V_ID: = TO_NUMBER (REPLACE (SUBSTR (city_row, 1, INSTR (city_row, separator) - 1) ', ' "',"));
V_NAME: = REPLACE (SUBSTR (city_row, INSTR (city_row, separator) + 1) ', ' "');
V_FNAME: = REPLACE (SUBSTR (city_row, INSTR (city_row, separator) + 1) ', ' "');


INSERT INTO test (V_ID, V_NAME, V_FNAME)
VALUES (ID, NAME, FNAME);
END IF;

END LOOP;

EXCEPTION
WHEN NO_DATA_FOUND THEN
NULL;
END;

TEXT_IO.fclose (file_handle);

COMMIT;

EXCEPTION
WHILE OTHERS THEN
message ('Error!');
-RESTORATION;
RAISE FORM_TRIGGER_FAILURE;
END;





THE PROBLEM IS

* OUTPUT *.

ID NAME FNAME
--------- ------------------------------ ------------------------------
2 Sani, ahmed Sani, ahmed
3 chuck, Chuck jhon jhon



'name' field of charge fname field with a comma...
anyone can correct the code


THANKS IN ADVANCE

concerning
Sajid

Published by: [email protected] on June 26, 2009 12:11 AM

Hello

Create a 'SPLIT', use function to get your chips:

  --------------------------
  --  get a string token  --
  --------------------------
 CREATE OR REPLACE FUNCTION SPLIT
 (
    PC$Chaine IN VARCHAR2,         -- input string
    PN$Pos IN PLS_INTEGER,         -- token number
    PC$Sep IN VARCHAR2 DEFAULT ',' -- separator character
 )
 RETURN VARCHAR2
 IS
   LC$Chaine VARCHAR2(32767) := PC$Sep || PC$Chaine ;
   LI$I      PLS_INTEGER ;
   LI$I2     PLS_INTEGER ;
 BEGIN
   LI$I := INSTR( LC$Chaine, PC$Sep, 1, PN$Pos ) ;
   IF LI$I > 0 THEN
     LI$I2 := INSTR( LC$Chaine, PC$Sep, 1, PN$Pos + 1) ;
     IF LI$I2 = 0 THEN LI$I2 := LENGTH( LC$Chaine ) + 1 ; END IF ;
     RETURN( SUBSTR( LC$Chaine, LI$I+1, LI$I2 - LI$I-1 ) ) ;
   ELSE
     RETURN NULL ;
   END IF ;
 END SPLIT;
/
DECLARE
  LC$Line  VARCHAR2(100) := '1,field1,field2' ;
  seperator VARCHAR2(2) := ',' ;
BEGIN
  DBMS_OUTPUT.PUT_LINE(SPLIT(LC$Line,1,','));
  DBMS_OUTPUT.PUT_LINE(SPLIT(LC$Line,2,','));
  DBMS_OUTPUT.PUT_LINE(SPLIT(LC$Line,3,','));
END;

François

Tags: Oracle Development

Similar Questions

  • load data from csv file into table

    Hello

    I'm working on Oracle 11 g r2 on UNIX platform.

    We have an obligation to load data to the table to a flat file, but on one condition, need to make the comparison between filed primary key if the file is available then update another filed and if the recording is not available, we need to insert.

    How can achieve us.

    SQLLoader to load the CSV file data into a staging Table.

    Then use the MERGE SQL command to the lines of insert/update of table setting for the target table.

    Hemant K Collette

  • CSV file loaded in ODI with fields of dd/mm/yyyy. But every month are crushed with 01 month (January) only

    Hi all

    I loaded a CSV source file for the target Oracle table. Mapping was properly executed, but the month of dd/mm/yyyy is only show 01, even if I have other months in my folder.

    Any ideas on that?

    Thank you!

    Hope this helps you

  • ODI - read CSV file and write to the Oracle table

    Hello world

    After 4 years, I started to work again with ODI, and I'm completely lost.

    I need help, I don't know what to use for each step, interfaces, variables, procedures...

    What I have to do is the following:

    (1) reading a CSV file-> I have the topologies and the model defined

    (2) assess whether there is a field of this CSV file in TABLE A-> who do not exist in the table is ignored (I tried with an interface joining the csv with the TABLE model a model and recording the result in a temporary data store)

    Evaluate 3) I need to update TABLE C and if not I need to INSERT if another field that CSV exists in TABLE B-> if there

    Could someone help me with what use?

    Thanks in advance

    Hi how are you?

    You must:

    Create an interface with the CSV template in the source and a RDBM table in the target (I'll assume you are using Oracle). Any type of filter or the transformation must be defined to be run in the stadium. (you must use a LKM for SQL file and add an IKM Sql control (it is best to trim them and insert the data when it cames to a file if you want after this process, you may have an incremental update to maintain history or something like that).)

    For validation, you will use a reference constraints in the model of the oracle table: (for this you need a CKM Oracle to check constraints)

    Then, you must select the table that you sponsor and in the column, you choose which column you will match.

    To article 3, you repeat the above process.

    And that's all. Pretty easy. If you do not have the two tables that you need to use your validation that you need to load before loading the CSV file you need valid.

    Hope this can help you

  • Performance problem when downloading the CSV files into Oracle tables

    We have implemented the Vikas solution ([http://htmldb.oracle.com/pls/otn/f?p=38131:1]) to download CSV files into tables Oracle permanent and it works fine. However, whenever we try to send more than 5,000 records, it takes a lot of time and often wait times. What can we do to improve performance? We are running HTMLDB 2.0.

    For example, a CSV file with 12000 documents and 40 columns takes 40 minutes to load (while a recording of CSV 2000 file takes 2 minutes to load).

    For large external files, copy us our CSV files to the Oracle server and then make reference to the file in an Oracle external table. Once the external table defined you then load your APEX table via a stored procedure by using:

    INSERT INTO your_tbl (columns)
    SELECT (columns)
    Of external_tbl

    Hope that gives you another option to consider.

    Jeff

  • Import a CSV file into a table

    Hello

    I followed this example to download the CSV file in table in the database.
    http://avdeo.com/2008/05/21/uploading-Excel-sheet-using-Oracle-Application-Express-apex/

    It seems that no file is saved in this table - wwv_flow_files

    When I run the procedure laid down in the above example, I get error "No data found".
    Please, help me.

    I use Oracle Apex version 4.0.2

    Thank you!

    See my sample application

    http://Apex.Oracle.com/pls/Apex/f?p=51467:1:3854972221692354:no:

    user: test password: test

  • CSV file problem

    Hi all

    I'm working on a CSV file interface Table.

    In my csv file, the data is

    Roll, name,address

    1,Street 1A, sf, 101, usa

    2, a, hyd Street, 1A, 500067, AP

    After the execution of the interface, the data loaded in the table as

    1 has 1 Street

    2A 1A Street

    I can't get all the data of the address column.

    Please let me know what should be the work around that.

    Thank you

    Lony

    If you see the comma in the section of the value (e.g. address) you better use double quotes as delimiter filed. If you see no delimiter in your file, you better ask your customer to provide files with double quotes as delimiter.

    Chantal

    http://dwteam.in

  • Get the error loading file csv to oracle table

    Hello

    I'm tryitng to load the csv file into oracle db table.

    Source:

    CSV file have account_numbers, customer_names. all the fields, it took as channel.

    Target: Oracle db

    If I took all the fields as varchar, it loads very well. but I want to

    Oracle table fields: digital account numbers or decimal (20.2)

    customer_names as varchar2 format.

    When I'm trying to load csv to oracle table, I am getting following error.

    err7.png

    ODI-1228: fgh1 (integration) task fails on the target odi_user1 ORACLE connection.

    Caused by: java.sql.SQLSyntaxErrorException: ORA-01722: invalid number

    I tried so many times. I am still getting error.

    TO_NUMBER function I also used, getting same error

    Please help me,

    Thank you and best regards,

    A.Kavya.

    Hi, String, CSV file data type have values of amount a 54,356,4657.89 format. Like this. In odi, I took number (30.2) of data types for the target table. When I traced in odi, I get error like invalid number. to do this, I changed the values in csv file format. I removed commas. for example, 543564657.89. Yet once, I traced csv to oracle in odi. executd successfully. Thanks & regards, A.kavya.

  • SQL Loader loading data into two Tables using a single CSV file

    Dear all,

    I have a requirement where in I need to load the data into 2 tables using a simple csv file.

    So I wrote the following control file. But it loads only the first table and also there nothing in the debug log file.

    Please suggest how to achieve this.

    Examples of data

    Source_system_code,Record_type,Source_System_Vendor_number,$vendor_name,Vendor_site_code,Address_line1,Address_line2,Address_line3

    Victor, New, Ven001, Vinay, Vin001, abc, def, xyz

    Control file script

    ================

    OPTIONS (errors = 0, skip = 1)
    load data
    replace
    in the table1 table:
    fields ended by ',' optionally surrounded "" "
    (
    Char Source_system_code (1) POSITION "ltrim (rtrim (:Source_system_code)),"
    Record_type tank "ltrim (rtrim (:Record_type)),"
    Source_System_Vendor_number tank "ltrim (rtrim (:Source_System_Vendor_number)),"
    $vendor_name tank "ltrim (rtrim (:Vendor_name)),"
    )
    in the Table2 table
    1 = 1
    fields ended by ',' optionally surrounded "" "
    (
    $vendor_name tank "ltrim (rtrim (:Vendor_name)),"
    Vendor_site_code tank "ltrim (rtrim (:Vendor_site_code)),"
    Address_line1 tank "ltrim (rtrim (:Address_line1)),"
    Address_line2 tank "ltrim (rtrim (:Address_line2)),"
    Address_line3 tank "ltrim (rtrim (:Address_line3)).
    )

    the problem here is loading into a table, only the first. (Table 1)

    Please guide me.

    Thank you

    Kumar

    When you do not provide a starting position for the first field in table2, it starts with the following after a last referenced in table1 field, then it starts with vendor_site_code, instead of $vendor_name.  So what you need to do instead, is specify position (1) to the first field in table2 and use the fields to fill.  In addition, he dislikes when 1 = 1, and he didn't need anyway.  See the example including the corrected below control file.

    Scott@orcl12c > test.dat TYPE of HOST

    Source_system_code, Record_type, Source_System_Vendor_number, $vendor_name, Vendor_site_code, Address_line1, Address_line2, Address_line3

    Victor, New, Ven001, Vinay, Vin001, abc, def, xyz

    Scott@orcl12c > test.ctl TYPE of HOST

    OPTIONS (errors = 0, skip = 1)

    load data

    replace

    in the table1 table:

    fields ended by ',' optionally surrounded "" "

    (

    Char Source_system_code (1) POSITION "ltrim (rtrim (:Source_system_code)),"

    Record_type tank "ltrim (rtrim (:Record_type)),"

    Source_System_Vendor_number tank "ltrim (rtrim (:Source_System_Vendor_number)),"

    $vendor_name tank "ltrim (rtrim (:Vendor_name)).

    )

    in the Table2 table

    fields ended by ',' optionally surrounded "" "

    (

    source_system_code FILL (1) POSITION.

    record_type FILLING,

    source_system_vendor_number FILLING,

    $vendor_name tank "ltrim (rtrim (:Vendor_name)),"

    Vendor_site_code tank "ltrim (rtrim (:Vendor_site_code)),"

    Address_line1 tank "ltrim (rtrim (:Address_line1)),"

    Address_line2 tank "ltrim (rtrim (:Address_line2)),"

    Address_line3 tank "ltrim (rtrim (:Address_line3)).

    )

    Scott@orcl12c > CREATE TABLE table1:

    2 (Source_system_code VARCHAR2 (13),)

    3 Record_type VARCHAR2 (11),

    4 Source_System_Vendor_number VARCHAR2 (27),

    5 $vendor_name VARCHAR2 (11))

    6.

    Table created.

    Scott@orcl12c > CREATE TABLE table2

    2 ($vendor_name VARCHAR2 (11),)

    3 Vendor_site_code VARCHAR2 (16).

    4 Address_line1 VARCHAR2 (13),

    5 Address_line2 VARCHAR2 (13),

    Address_line3 6 VARCHAR2 (13))

    7.

    Table created.

    Scott@orcl12c > HOST SQLLDR scott/tiger CONTROL = test.ctl DATA = test.dat LOG = test.log

    SQL * Loader: release 12.1.0.1.0 - Production on Thu Mar 26 01:43:30 2015

    Copyright (c) 1982, 2013, Oracle and/or its affiliates.  All rights reserved.

    Path used: classics

    Commit the point reached - the number of logical records 1

    TABLE1 table:

    1 row loaded successfully.

    Table TABLE2:

    1 row loaded successfully.

    Check the log file:

    test.log

    For more information on the charge.

    Scott@orcl12c > SELECT * FROM table1

    2.

    RECORD_TYPE SOURCE_SYSTEM_VENDOR_NUMBER $VENDOR_NAME SOURCE_SYSTEM

    ------------- ----------- --------------------------- -----------

    Victor Ven001 new Vinay

    1 selected line.

    Scott@orcl12c > SELECT * FROM table2

    2.

    $VENDOR_NAME VENDOR_SITE_CODE ADDRESS_LINE1 ADDRESS_LINE2 ADDRESS_LINE3

    ----------- ---------------- ------------- ------------- -------------

    Vinay Vin001 abc def xyz

    1 selected line.

    Scott@orcl12c >

  • Read data from the Table and load it into the csv file

    Hello

    I would like to read a table (select * from employees) and load the data into a csv file.

    What methods are available?

    Records will be at high volume.

    Thank you

    If it is to do a lot, use APEX.

    Create a new page with an interactive report based on the SQL code you want. When you go to download Excel, it is actually a CSV file.

    If it is large, you may need to go on the FILE_UTL road.

    If it is only once, use an interface such as SQL tool * or SQL * Developer.

    If it's a learning experience, you must do all three.

    MK

  • Load a CSV file into a table like in dataworkshop

    Workshop of data has a function to load a CSV file and create a table based on it, the same, I want to create in my application.



    I went through the forum http://forums.oracle.com/forums/thread.jspa?threadID=334988 & start = 60 & tstart = 0

    but not able to download all the files (application, package HTMLDB_TOOLS and PAGE_SENTRY function) could not find the PAGE_SENTRY function.

    AND when I open this link http://apex.oracle.com/pls/apex/f?p=27746

    I could not run the application. I've provided a CSV file and when I click on SEND, I get the error:

    ORA-06550: line 1, column 7: PLS-00201: identifier ' HTMLDB_TOOLS. PARSE_FILE' must be declared

    tried in apex.oracle.com host as shown in the previous post.

    any help pls..,.

    Another method to load data into the tables..., (as dataworkshop)

    Hello

    I have check app works very well.

    Have you read instructions?
    Load a CSV file in a table
    >
    Create a small csv file as

    col1, col2, col3
    VARCHAR2 (10), Number, "Number (10.2)" "
    Cat, 2, 3.2
    dog, 99, 10.4
    >
    First row must have valid column names. To verify that your first line of titles have no spaces or those who are not words reserved.
    Second line of the CSV file must have column of table data types.

    When you meet these requirements app works perfectly

    Kind regards
    Jari

  • Not able to load csv file CLOB columns in table

    Hello

    I'm trying to load a table with the Source file CLOB columns which is in .csv format. I get the following messages

    "SQL * Loader-292: setting LINES ignored when an XML, VARRAY or LOB column is loaded.

    Can anyone help me on how to proceed with my load of data.

    Thank you!!!

    Hello

    Ignore "SQL * Loader-292: setting LINES ignored when loading an XML, VARRAY or LOB column" error

    After you import your csv file just change the length CHAR (100000).

    ex: your column col1 CHAR (1000) to change CHAR (100000).

    and deploy your mapping and execution

    Kind regards
    Vincent

  • Creating a table to a csv file

    I use the JDeveloper 11.1.1.6.

    I'm looking to recover data to a .csv file and load it into a custom table made just for the data in the file.

    I managed to load the csv file in a data control with a Service URL data control. I wonder how to take data from the data control and place it in a Java object so that I can make the dynamic creation of sql create statement table. I know how to do dynamic creation - it's just to access the data of the data control to which I am at this point.

    If there is a better way to do it, I would be also open to it! Thank you!

    Published by: Jim W. 26 September 2012 08:00

    I found this documentation. Is not myself. The documentation is newer than your version, so it may not work.

    http://docs.Oracle.com/CD/E24382_01/Web.1112/e16182/bcquerying.htm

    Stuart

  • Load the CSV file

    I use Apex 3.2 and construction of a facility charge of csv file.
    I received a lot of help on this post
    Re: Validate CSV File
    I'm now able to load the data into my custom table.
    Before I do that I want to update the collection first, using this option if statement
    IF c001 IS NULL THEN
                c006    := 'APXIMP';
                c007    := c007 || 'Storekey is missing!';
              END IF;
    
              IF c002 IS NULL THEN
                c006    := 'APXIMP';
                c007    := c007 || 'Plan Delivery Moment is missing!';
              END IF;
    
              IF c003 IS NULL THEN
                c006    := 'APXIMP';
                c007    := c007 || 'WRIN Base is missing!';
              END IF;
    
              IF c004 IS NULL THEN
                c006    := 'APXIMP';
                c007    := c007 || 'WRIN Suffix is missing!';
              END IF;
    
              IF c005 IS NULL THEN
                c006    := 'APXIMP';
                c007    := c007 || 'Order Qty. is missing!';
              END IF;
    
              IF c005 IS NOT NULL THEN
                IF SIGN(vt_record(5))=-1 THEN
                  c006    := 'APXIMP';
                  c007    := c007 || 'Order Qty. must be a positive integer value!';
                END IF;
                IF MOD(c005,FLOOR(c005)) <> 0 THEN
                  c006    := 'APXIMP';
                  c007    := c007 || 'Order Qty. must be a positive integer value!';
                END IF;
              END IF;
            EXCEPTION
              WHEN others THEN
                c006    := 'APXIMP';
                c007    := c007 || 'Order Qty. must be a positive integer value!';
    I am new to the collections, so if someone could show me an example or point me in the right direction, as there seems to be several types of update of collection procedures.

    See you soon

    Gus

    Hello

    You talk about the package but written the anonymous block syntax. I did understand what you're trying to do.

    Assuming that it is a procedure of your code should look like

    CREATE OR REPLACE PROCEDURE UPDATE_COLL (
      P_collection_name IN VARCHAR2  -- parameter passed when calling from Apex Process
    ) AS
    
    begin
    
    for x in (select seq_id, c001, c002, c003, c004, c005, c006, c007
             from apex_collections
            where collection_name = p_ collection_name )
    LOOP
    
         IF x.c001 IS NULL THEN
          apex_collection.update_member_attribute (
             p_collection_name=> p_collection_name,
             p_seq=> x.seq_id,
             p_attr_number =>6,
             p_attr_value=> 'APXIMP'
            );
           apex_collection.update_member_attribute (
              p_collection_name=> p_collection_name,
              p_seq=> x.seq_id,
             p_attr_number =>7,
             p_attr_value=> x.c007 || 'Storekey is missing!'
          );
         END IF;
    
        IF x.c002 IS NULL THEN
          apex_collection.update_member_attribute (
             p_collection_name=> p_collection_name,
             p_seq=> x.seq_id,
             p_attr_number =>6,
             p_attr_value=> 'APXIMP'
            );
           apex_collection.update_member_attribute (
              p_collection_name=> p_collection_name,
              p_seq=> x.seq_id,
             p_attr_number =>7,
             p_attr_value=> x.c007 ||  'Plan Delivery Moment is missing!'
          );
         END IF;
    
        IF x.c003 IS NULL THEN
          apex_collection.update_member_attribute (
             p_collection_name=> p_collection_name,
             p_seq=> x.seq_id,
             p_attr_number =>6,
             p_attr_value=> 'APXIMP'
            );
           apex_collection.update_member_attribute (
              p_collection_name=> p_collection_name,
              p_seq=> x.seq_id,
             p_attr_number =>7,
             p_attr_value=> x.c007 ||   'WRIN Base is missing!'
          );
        END IF;
    
        IF x.c004 IS NULL THEN
          apex_collection.update_member_attribute (
             p_collection_name=> p_collection_name,
             p_seq=> x.seq_id,
             p_attr_number =>6,
             p_attr_value=> 'APXIMP'
            );
           apex_collection.update_member_attribute (
              p_collection_name=> p_collection_name,
              p_seq=> x.seq_id,
             p_attr_number =>7,
             p_attr_value=> x.c007 ||  'WRIN Suffix is missing!'
          );
       END IF;
    
      IF x.c005 IS NULL THEN
          apex_collection.update_member_attribute (
             p_collection_name=> p_collection_name,
             p_seq=> x.seq_id,
             p_attr_number =>6,
             p_attr_value=> 'APXIMP'
            );
          apex_collection.update_member_attribute (
              p_collection_name=> p_collection_name,
              p_seq=> x.seq_id,
             p_attr_number =>7,
             p_attr_value=> x.c007 || 'Order Qty. is missing!'
          );
      END IF;
    
      IF x.c005 IS NOT NULL THEN
          IF SIGN(c005)=-1 THEN
          apex_collection.update_member_attribute (
             p_collection_name=> p_collection_name,
             p_seq=> x.seq_id,
             p_attr_number =>6,
             p_attr_value=> 'APXIMP'
            );
          apex_collection.update_member_attribute (
              p_collection_name=> p_collection_name,
              p_seq=> x.seq_id,
             p_attr_number =>7,
             p_attr_value=> x.c007 || 'Order Qty. must be a positive integer value!'
          );
         END IF;
         IF MOD(c005,FLOOR(c005))  0 THEN
          apex_collection.update_member_attribute (
             p_collection_name=> p_collection_name,
             p_seq=> x.seq_id,
             p_attr_number =>6,
             p_attr_value=> 'APXIMP'
            );
          apex_collection.update_member_attribute (
              p_collection_name=> p_collection_name,
              p_seq=> x.seq_id,
             p_attr_number =>7,
             p_attr_value=> x.c007 ||'Order Qty. must be a positive integer value!'
          );
        END IF;
      END IF;
    END LOOP;
     EXCEPTION
              WHEN others THEN
          apex_collection.update_member_attribute (
             p_collection_name=> p_collection_name,
             p_seq=> x.seq_id,
             p_attr_number =>6,
             p_attr_value=> 'APXIMP'
            );
          apex_collection.update_member_attribute (
              p_collection_name=> p_collection_name,
              p_seq=> x.seq_id,
             p_attr_number =>7,
             p_attr_value=> x.c007 || 'Order Qty. must be a positive integer value!'
          );
    end;
    
  • Import from CSV file into oracle using pl/sql - sql loader 3.1

    Hello

    I am trying to learn how to import a CSV file in an oracle table. I tried the import utility in SQL Loader, but it generates specific lines of code to import each line. I would like a loop to go through the CSV file stored on my local disk and transferred it to my table.

    I tried the following, but not luck
    DOWNLOAD THE DATA
    INFILE 'sample_csv.csv '.
    IN THE TEST TABLE
    FIELDS TERMINATED BY ', '.
    ;

    951716 wrote:
    Hello

    I am trying to learn how to import a CSV file in an oracle table. I tried the import utility in SQL Loader, but it generates specific lines of code to import each line. I would like a loop to go through the CSV file stored on my local disk and transferred it to my table.

    line-by-line is slow by slow.
    PL/SQL will be NEVER faster than simple SQL
    INSERT INTO MYTABLE SELECT * FROM EXTERNAL_TBL;

    http://www.orafaq.com/wiki/External_table

Maybe you are looking for