CSV file data load

Hi All,
I have a CSV file having data in cell. I have to load the csv file data in supporting table.
In code, I will pass parameters as - csv file name, path and supporting table name that required inserting the file data. (This is just a sample code; I required handling many things)
My Sample CSV file data: (Data are comma separated) ,In file in third,have null value ,Plese help to handle null values in below code while inserting.
1,AB,1/1/2013
2,CD,1/1/2012
3,<null>,1/1/2013Sample Code:
DECLARE
    v_csvfile       VARCHAR2(30) := 'temp.csv';--<<This is the csv file name>>
    v_csvpath       VARCHAR2(30) := --<<This is the path>>
    v_csvtab        VARCHAR2(30) := 'TEMP';
    v_csvdata       VARCHAR2(32767);
    v_csveof        BOOLEAN := FALSE;
    v_csvfilehandle utl_file.file_type;
    v_str           VARCHAR2(32767);
BEGIN
    v_csvfilehandle := utl_file.fopen(v_csvpath, v_csvfile, 'r', 32767);
    WHILE NOT v_csveof
    LOOP
        BEGIN
            utl_file.get_line(v_csvfilehandle, v_csvdata);
            FOR i IN (SELECT s.data_type, s.internal_column_id
                        FROM user_tab_cols s
                       WHERE s.table_name = UPPER(v_csvtab)
                       ORDER BY internal_column_id)
            LOOP
                IF i.data_type = 'DATE'
                THEN
                    v_str := v_str || 'TO_DATE (' || ' REGEXP_SUBSTR( ' || '''' ||
                             v_csvdata ||
                             '''' || ' ,' || '''' || '[^,]+' || '''' ||
                             ' ,1,' || i.internal_column_id || ' ),' || '''' ||
                             'MM/DD/YYYY' || '''' || ' )';
                ELSE
                    v_str := v_str || ' REGEXP_SUBSTR( ' || '''' ||
                             v_csvdata ||
                             '''' || ' ,' || '''' || '[^,]+' || '''' ||
                             ' ,1,' || i.internal_column_id || ' ),';
                END IF;
            END LOOP;
                    --DBMS_OUTPUT.put_line('INSERT INTO  ' || v_csvtab || ' VALUES ( ' || v_str || ' )');
            EXECUTE IMMEDIATE 'INSERT INTO  ' || v_csvtab || ' VALUES ( ' || v_str || ' )';
                              v_str := NULL;
        EXCEPTION
            WHEN no_data_found THEN
                v_csveof := TRUE;
        END;
    END LOOP;
    utl_file.fclose(v_csvfilehandle);
EXCEPTION
    WHEN OTHERS THEN
        dbms_output.put_line(dbms_utility.format_error_backtrace ||
                             ' Err ' || SQLERRM);
        RAISE;
END;Script to create sample supporting table:
CREATE TABLE TEMP
(col1 VARCHAR2(100),
col2 VARCHAR2(100),
col3 DATE );Thanks,

Don't re-invent the wheel.
If your CSV is on the database server (it must be if you are using UTL_FILE), use an external table
http://docs.oracle.com/cd/E11882_01/server.112/e22490/et_concepts.htm#SUTIL011
If your CSV is on a client PC, use Sql*Loader
http://docs.oracle.com/cd/E11882_01/server.112/e22490/ldr_concepts.htm#SUTIL003

Similar Messages

  • CSV  file data load error

    Hi,
    Data load from Flat File.
    The master data is loaded using CSV file.
    Emp ID;  in source file it is replesented as 1,2,3..10...1009
    But when i load the data it is being converted to 0000000001,0000000002....etc
    The info object Data Type is Char and Length is 10 and Conversion Routine is none
    I want it to be loaded as 1,2,3... as it is as it is in source file
    Thanks

    Hi,
    Right click on that cell -> Format cells - > Number (tab) -> select Text and click OK.
    Hope this helps.
    PB

  • Load .csv file data with OWb Process flow using Web

    Hi,
    I Have a file in my local machine( Machines on multiple user's), need to load data through Web user interface.
    Let's say have a web page with multiple radio buttons respective to different sources, by clicking on each button will pass the path of .csv file to through Application, (API or Java programming interface) execute owb Process flow as a accepting file path as a input parameter to execute for loading purpose.
    Should facilitate view data, Update data through web based on user requests.
    Need your guidence how can i implement this with OWb 11g R2.
    Assuming with Web browser functionality. Please confirm it and if yes, please throw some light how could be the steps to implement.
    Thanks

    Hi David,
    Thanks for your reply.
    Undersatnd your proposed solution.But my requirement should be as follows.
    1. Currently under consideration using web page likely to be implement with Java, allowing users to load .csv file data into staging area.(Loading flat file into Data abse table)
    Case 1, Assuming OWB software is not installed on user machine. I think no.
    Is it possible through web page (this case Java page) to trigger java procedure/Pl/SQl procedure or integration of both to laod data into staging area.If yes, how it could effect performance of data load with 1 GB file.
    Case 2, OWb client software installed on User machine, while runtime passing parameters means passing manually?
    In case it is automated, how should i pass machine name & Path to owb runtime web browser.
    Could you please show me guidence how should I acheive this functionality with APEX customization part?
    Thanks agin for your support.
    Anil

  • Flat File Data Loads to BI 7.0

    Hi Experts,
    Please update me what is the best approach i have to follow for the below scenario of Flat File Data Loads
    I will get data in Excel ....with Two worksheets....from the user
    My requirment is to place the file in Central location avaliable to the user and BW to update if any changes necessary  and want to load data(full0  to bw from file if there are any changes
    Please update me how to deal with this scenarion of Two work sheets,In a central location...
    Thanks

    Easiest thing would be to use a DSO with change log to handle the changes to pass onto to any cubes and load a full every night
    Then let the change log worry about any changes to the workbook
    You have to be careful about the DSO keys though for this to work properly
    Now to automate the loads - just how are you planning to create the infopackage as it will only read a csv and not the binary xls
    Well it will read the binary xls if you maybe use a dbconnect with a jdbc driver to read the xls (that's on my next thing to do - but if you are as your user id suggests a "bw learner" then that may be a bit complicated)
    The only other thign to do is to write a macro that automatically creates the csv file on the app server when the user quits the xls
    Or off course you can just dump the csv each night - but then that is a manual task and in systems I design I hate manual tasks as staff go on holiday and peopel change jobs and it's not really very SoX compliant

  • Related to CSV file data upload

    Hi all,
    I am new to the oracle technology.
    While uploading the data from csv file i got this error
    "SQL*Loader-350: Syntax error at line 4.
    Expecting keyword TABLE, found "xxgfs_gen_text_lookups".
    APPEND INTO xxgfs_gen_text_lookups"
    my csv file data is
    Invoice Match Options,,,Invoice,,
    Invoice Match Options,,,Receipt,,
    Invoice Match Options,,,Purchase Order,,X
    Invoice Type,A 00,Advance,Standard,Standard invoice,
    Invoice Type,B 00,Expense,Standard,Standard invoice,
    Invoice Type,2 00,Debit Memo,Credit Memo,Credit Memo,
    Invoice Type,2 20,EDI Debit Memo,Credit Memo,Credit Memo,
    Invoice Type,1 00,Invoice,Standard,Standard invoice,
    Invoice Type,1 01,Arrow Credit,Standard,Standard invoice,,
    Invoice Type,1 10,Recurring Payments,Standard,Standard invoice,,
    Invoice Type,1 20,EDI Invoices,Standard,Standard invoice,,
    Invoice Type,1 21,Imaged Invoice,Standard,Standard invoice,X,Default when entering from form
    Invoice Tax Code,XMT,DO NOT USE,,,,
    Invoice Tax Code,STE,DO NOT USE,,,,
    Invoice Tax Code,,,,,,
    Invoice Tax Code,,,,,,
    Invoice Tax Code,,,,,,
    Invoice Tax Code,,,,,,
    Invoice Tax Code,,,,,,
    Invoice Tax Code,,,,,,
    Invoice Tax Code,,,,,,
    Invoice Tax Code,,,,,,
    Invoice Tax Code
    If i am removing the blank row then also it is giving the same problem.
    If anybody face the same problem then please help me out.
    thanks in advance to u all for ur help.
    -Rajnish

    This is the Oracle Application Express (formerly known as HTML DB) forum. SQL*Loader related questions should be asked in the Database SQL forum (PL/SQL or Database General Forum (General Database Discussions but being a nice guy familiar with SQL*Loader I will "give it a go".
    The error message you are getting indicates that you have a syntax error in your control file. The syntax for the APPEND keyword is APPEND INTO TABLE table_name. So change "APPEND INTO xxgfs_gen_text_lookups" to "APPEND INTO TABLE xxgfs_gen_text_lookups".
    Mike

  • CSV file data upload problem

    Hi all,
    I am new to the oracle technology.
    While uploading the data from csv file i got this error
    "SQL*Loader-350: Syntax error at line 4.
    Expecting keyword TABLE, found "xxgfs_gen_text_lookups".
    APPEND INTO xxgfs_gen_text_lookups"
    my csv file data is
    Invoice Match Options,,,Invoice,,
    Invoice Match Options,,,Receipt,,
    Invoice Match Options,,,Purchase Order,,X
    Invoice Type,A 00,Advance,Standard,Standard invoice,
    Invoice Type,B 00,Expense,Standard,Standard invoice,
    Invoice Type,2 00,Debit Memo,Credit Memo,Credit Memo,
    Invoice Type,2 20,EDI Debit Memo,Credit Memo,Credit Memo,
    Invoice Type,1 00,Invoice,Standard,Standard invoice,
    Invoice Type,1 01,Arrow Credit,Standard,Standard invoice,,
    Invoice Type,1 10,Recurring Payments,Standard,Standard invoice,,
    Invoice Type,1 20,EDI Invoices,Standard,Standard invoice,,
    Invoice Type,1 21,Imaged Invoice,Standard,Standard invoice,X,Default when entering from form
    Invoice Tax Code,XMT,DO NOT USE,,,,
    Invoice Tax Code,STE,DO NOT USE,,,,
    Invoice Tax Code,,,,,,
    Invoice Tax Code,,,,,,
    Invoice Tax Code,,,,,,
    Invoice Tax Code,,,,,,
    Invoice Tax Code,,,,,,
    Invoice Tax Code,,,,,,
    Invoice Tax Code,,,,,,
    Invoice Tax Code,,,,,,
    Invoice Tax Code
    If i am removing the blank row then also it is giving the same problem.
    If anybody face the same problem then please help me out.
    thanks in advance to u all for ur help.
    -Rajnish

    Running SQL*Loader as:
      sqlload userid=... control=... data=... log=...
    HOSTSTR logical has been set to same value as your connection string but
    without domain name.
    When you have specified connect string (ie. SCOTT/TIGER@DATABASE) but no
    domain you receive these errors:
      SQL*Loader-704: Internal error: ulconnect: OCIServerAttach [0]
      ORA-12154: TNS:could not resolve service name
    When you have not specified connect string (ie. SCOTT/TIGER) you receive
    these errors:
      SQL*Loader-704: Internal error: ulconnect: OCIServerAttach [0]
      ORA-12162: TNS:service name is incorrectly specified
    Your sqlnet.ora has:
      names.default_domain entry = world
    The syntax in your tnsnames.ora entry is correct.
    Your entry in tnsnames.ora does not include the .WORLD extension (default
    domain from sqlnet.ora).
    Solution Description
    Specify the .WORLD in your tnsnames.ora and also in your connect string.
    This will remove the error.
    Also, ensure you are not hitting Bug 893290.  Can you connect to the database from that server using sqlplus?

  • Stage tab delimited CSV file and load the data into a different table

    Hi,
    I pretty new to writing PL/SQL packages.
    We are using Application express for our development. We get CSV files which is stored as a BLOB content in a table. I need to write a trigger that would get executed once the user the uploads the file and parse thru the Blob content and upload or stage the data in a different table.
    I would like to see if there is any tutorial or article that could explain the above process with the example or sample code to do the same. Any help in this regard will be highly appreciated.

    Hi,
    This is slightly unusual but at the same time easy to solve. You can read through a blob using the dbms_lob package, which is one of the Oracle supplied packages. This is presumably the bit you are missing, as once you know how you read a lob the rest is programming 101.
    Alternatively, you could write the lob out to a file on the server using another built in package called utl_file. This file can be parsed using an appropriately defined external table. External tables are the easiest way of reading data from flat files, including csv.
    I say unusual because why are you loading a csv file into a blob? A clob is almost understandable but if you can load into a column in a table why not skip this bit and just load the data as it comes in straight into the right table?
    All of what I have described is documented functionality, assuming you are on 9i or greater. But you didn't provide a version so I can't provide a link to the documentation ;)
    HTH
    Chris

  • Flat file data load error: Exception with type CX_SY_CONVERSION_NO_NUM

    Hi Guys,
    I am trying to create a datasource from a flat file (excel data in csv format) and when I create infopackage on the datasource and trying to load, I am getting the error,
    Error 'An exception with the type CX_SY_CONVERSION_NO_NUM' at conversion exit RSDS_CONVERT_NUMBER (field FAB record 480, value 8)
    Can somebody help me with this.
    I am working in BI 7. In the excel sheet I have all cell with general format.
    I tried using PSA Typed and not Typed. Didnt work
    Thanks in advance

    I selected Data Format as "Separated with Separated (for Example CSV),
    Data Separator ,
    Escape Sign ; (this i didnt understand where it comes in csv file) also I left the  Hex check boxes unchecked.
    PSA not Typed is also unchecked.
    Am I missing something? Data types in excel spreadsheet (csv file)?
    Thank you

  • Flat file data loading error using process chain

    Hi SAP Experts,
    I am having a problem loading the flat file data to the cube using process chain. The issue is that when i run the process chain it fails giving the message " Date format error, please enter the date in the format  _.yyyy" . I am using " 0calmonth in the datasource" . Strange is that when i manually execute the infopackage, i dont get any errors and am able to load the same file successfully to the dso and the cube. Is there any special setting for the process chain that i am missing?
    The date format in the flat file is mm/yyyy. I have tried all the options i could including recreating the datasource and invain dont see any success so far. please help me solving this problem as we r in the middle of testing cycle.
    Thanking you all for your quick response and support all the time.
    Kind Regards,
    Sanjeev

    Hi Sanjeev,
    I believe you are opening the .csv file again after saving it. In this case the initial 0 in single digit month (say 02/2010) is getting changed to 2/2010 and the resulting file is not readable to the system. Just do not open the file after you have entered data in the .csv file and saved and closed it. If required, open the file in notepad, but not in excel in case you want to re-check the data.
    Hope this helps.
    regards,
    biplab

  • How can I make an easy *.CSV file to load into database table

    Hi All,
    I have a huge excel sheet having columns item#, description and qty. The description column sometimes maybe one word name, two word name separated with space or may be , spearated name. I want to write and PL/SQl code which will read this file and load it into database table. Now the *.CSV file is either comma delimited or tab text delmited which both do not solve my issue. Is there any better solution with anyone which can prevent the manual editing to the *.CSV file and I can easily load it to table.
    Your help is appreciated,
    Thanks
    Zahir

    SQL*Loader is probably the fastest method, but since you specifically asked for a PL/SQL method:
    http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:464420312302

  • Flat file data load - ODS - Look up data in Startroutine

    Hi All,
    There is a requirement that I have two ODS say 1) ABC and XYZ.
    For Both ODS , We load flat file data.
    First we load data to ABC for current fiscal period
    During the data load to XYZ, We lookup part nos data in ABC for current fiscal period , if data there , for those part nos we load XYZ Flat file data.
    My requirement is that , I need to fetch part nos data from ABC for Fiscal period < current fisacl period.  Then I need to extract already loaded data for those part nos from XYZ and Mark the flag field as Non reportable .
    How can we achieve this ?
    Please advice
    Thanks
    Ajay

    Hi ,
    Thanks for your reply.
    I have done so. When I add lines of My Internal table data to DATA_PACKAGE, It gives the syntax error that both structures are not unique. We have several fields in XYZ ods but they are not in Communication structure.
    Thats the problem. Also , if I write the code , will it be executed for each datapackage. I mean , for each datapacket process , my code will fetch whole data from ABC and then from XYZ. Repetion will be there?
    Any other logic can i use ?
    Thanks
    Ajay

  • Commas in my CSV file data

    Hi everyone,
    I am trying to create a csv file.
    One field that I am trying to out put is the description and has commas, that is throwing my columns out of sync.
    I have tries putting the charactor ' around the data but all it does is output that charactor in the data.
    my code is this
         public File createFile(Vector downloadObject){
              Iterator iterator = downloadObject.iterator();
              String query ="";
              try {
                   Format formatter2 = new SimpleDateFormat("ddMMyyyy");
                   String fileName="DELIVERY" + ".csv";
                   File file = new File(fileName);
                   StringBuffer output = new StringBuffer();
                   while (iterator.hasNext()){
                        VODownloadObject downloadObject2 = (VODownloadObject)iterator.next();
                        query =
                             "'" +
                             downloadObject2.getStrokeNumber().trim()
                             + "','"+ downloadObject2.getJdeIdNumber()
                             + "','"+ downloadObject2.getRollNumber()
                             + "','"+ downloadObject2.getSupplier()
                             + "',"+ ",'"+ downloadObject2.getQuality()
                             + "','"+ downloadObject2.getColour()
                             + "','"+ downloadObject2.getSupplierRollNumber()
                             + "',"+ ",'"+ downloadObject2.getDeliveryDate()
                             + "','"+ downloadObject2.getFabricComposition()
                             + "',"+ ","+ ",'"+ downloadObject2.getTicketLength()
                             + "','"+ downloadObject2.getTicketWidth()
                             + "',"+ ","+ ","+ ",";
                        output.append(query + "\r\n");
                   BufferedWriter out = new BufferedWriter(new FileWriter(fileName));
                   out.write(output.toString());
                   out.close();
                   return file;
              } catch (IOException e) {
                   e.printStackTrace();
                   return null;
         }the output is this.
    'PA?????T','2/664659 ','153920','Menswear Formal, Shirts ',,'null','null',' ',,'11/07/2006','null',,,'-330000',' ',
    in the "'Menswear Formal, Shirts " field, this is one field but it is splitting up into 2 fields because there is a comma after Formal. Anyone know how I can keep this as one field but with a comma in it?
    thanks in advance

    I have abandoned my last appoach altogether
    I am using com.Ostermiller.util.CSVPrinter
    here is my final working class
         public File createFile(Vector downloadObject){
              Iterator iterator = downloadObject.iterator();
              String query ="";
              try {
                   Format formatter2 = new SimpleDateFormat("ddMMyyyy");
                   String fileName="DELIVERY" + ".csv";
                   File file = new File(fileName);
                   BufferedWriter out = new BufferedWriter(new FileWriter(fileName));
                   ExcelCSVPrinter ecsvp = new ExcelCSVPrinter(
                             out
                   while (iterator.hasNext()){
                        VODownloadObject downloadObject2 = (VODownloadObject)iterator.next();
                        String quality = " ";
                        if (downloadObject2.getQuality()!=null){
                             quality = downloadObject2.getQuality().trim();
                        String colour = " ";
                        if (downloadObject2.getColour()!=null){
                             colour = downloadObject2.getColour().trim();
                        String fabricComposition = " ";
                        if (downloadObject2.getFabricComposition()!=null){
                             fabricComposition =downloadObject2.getFabricComposition().trim();
                        ecsvp.writeln(new String [] {
                                   downloadObject2.getStrokeNumber().trim(),downloadObject2.getJdeIdNumber().trim(),
                                   downloadObject2.getRollNumber(), downloadObject2.getSupplier().trim(), " " ,
                                   quality , colour , downloadObject2.getSupplierRollNumber().trim() , " ",
                                   downloadObject2.getDeliveryDate().trim(), fabricComposition , " ", " ",
                                   downloadObject2.getTicketLength(), downloadObject2.getTicketWidth().trim(),
                   out.close();
                   return file;
              } catch (IOException e) {
                   e.printStackTrace();
                   return null;
         }

  • XML file data load to NW2004s-BI

    HI,
    I am trying to load the XML file data to NW2004s-BI .
    I have created the file Data source, infosoucrce and data store object. I have maintained the transformation rule for data source and info source also for infosource and data store object.
    But I am not able to create the XML DataSource (BW DataSource with SOAP Connection)
    Could any one please help me
    Thanks in advance.
    Amit

    Amit 
    Welcome to SDN.
    I don't know whether you checked this or not
    Select your Infosource>right click change>goto Extras-->and select Create BW Data source with SOAP Connection. It will crete Datasource.
    Hope this helps
    Thanks
    Sat
    PS: Don't forget to assign points if the answer is useful. This is the way of telling thanks in SDN

  • Upload csv file data to sql server tables

    Hi all,
    I want clients to upload csv file from their machines to the server.
    Then the program should read all the data from the csv file and do a bulk insert into the SQL Server tables.
    Please help me of how to go about doing this.
    Thanx in advance.....

    1) Use a multipart form with input type="file" to let the client choose a file.
    2) Get the binary stream and put it in a BufferedReader.
    3) Read each line and map it to a DTO and add each DTO to a list.
    4) Persist the list of DTO's.
    Helpful links:
    1) http://www.google.com/search?q=jsp+upload+file
    2) http://www.google.com/search?q=java+io+tutorial
    3) http://www.google.com/search?q=java+bufferedreader+readline
    4) http://www.google.com/search?q=jdbc+tutorial and http://www.google.com/search?q=sql+tutorial

  • Manipulate CSV File Data

    Hello,
    Our Active Directory structure only lists the person's manager in the format of an email address. After running a Get-ADUser command and exporting its data to a csv file. I want to import the csv file which will be in the format shown below, then manipulate
    it, so the manager1 field is converted to the relevant objectGUID and populated in the Manager_objectGUID field.
    I'm completely new to PowerShell so any assistance would be much appreciated.
    Thanks
    Stuart

    $OldCSV = "C:\OldADUsers.csv"
    $NewCSV = "C:\NewADUsers.csv"
    Add-Content $OldCSV "objectGUID,mail,givenName,sn,manager1,Manager_objectGUID"
    Add-Content $OldCSV "7c1be78f,[email protected],Mickey,Mouse,,"
    Add-Content $OldCSV "982874ab,[email protected],Donald,Duck,[email protected],"
    $ADUsers = Import-CSV $OldCSV
    # collect managers
    $Managers = @{}
    ForEach ($ADUser in $ADUsers)
    $Managers.Add($ADUser.Mail,$ADUser.ObjectGUID)
    # Get Managers
    ForEach ($ADUser in $ADUsers)
    IF ($ADUser.manager1 -NE "")
    If ($Managers[$ADUser.manager1] -NE $Null)
    $ADUser.Manager_objectGUID = $Managers[$ADUser.manager1]
    $ADUsers | Export-CSV $NewCSV
    Get-Content $NewCSV
    Gives this output
    #TYPE System.Management.Automation.PSCustomObject
    "objectGUID","mail","givenName","sn","manager1","Manager_objectGUID"
    "7c1be78f","[email protected]","Mickey","Mouse","",""
    "982874ab","[email protected]","Donald","Duck","[email protected]","7c1be78f"

Maybe you are looking for

  • Workflow related to personnel administration.

    Hi Everyone,                      I m in sap-hr and wanted to know that is there  any workflow related to personnel administration.Also how can I create a workflow for filling the personnel data of employees.I had created workflow for leave.         

  • ID 9.2 is very slow. Other CC programs run at normal speed.

    I have a document of 40 pages, most of which are blank, but operations are very slow. It may take 10 seconds for a 1500 x 750 pixel Photoshop image to appear during a Place operation after the box designating the size of the picture has been drawn wi

  • Expense Reimbursement Groups - France

    Hi, into the documentation related to the August release (i.e.: WHATS_NEW_ALL_en.pdf) is mentioned that for Country France it's now possibile to claim per diem rates for meals and lodging on a trip. I've activated into the Project Scope the country F

  • Photobooth question - selecting more than 1 photo

    Hi All, so a few weekends ago, i spend it with my friends kids and played around with photobooth....they loved it....but 200+ photos later whew!!!! So I've edited them down to about 60 and want to email them to my friend so that the kids can look and

  • Sap mii JRA proxy error when calling a BAPI

    Hi everyone, I am trying to connect SAP Netweaver (MII JAVA Stack only) to ECC via JRA. Everything was right (deployment and configuration) but when developers try to call a BAPI the following error appears: JRAProxy error. Entry not found. Could you