How get a correct CSV file

Hi,
I've this table:
CREATE TABLE TAB_BW (
COD VARCHAR2 (2),
COD_ID VARCHAR2 (20),
DESCRIPTION VARCHAR2 (64),
AREA NUMBER);
with these data:
INSERT INTO TAB_BW ( COD, COD_ID, DESCRIPTION, AREA ) VALUES (
'00', '000099', 'MY HOME', 21.654);
INSERT INTO TAB_BW ( COD, COD_ID, DESCRIPTION, AREA ) VALUES (
'01', '001234', 'MY HOME, MY DOG', 2111.3232);
INSERT INTO TAB_BW ( COD, COD_ID, DESCRIPTION, AREA ) VALUES (
'11', '033333', 'OK, NO', 1222.22);
INSERT INTO TAB_BW ( COD, COD_ID, DESCRIPTION, AREA ) VALUES (
'03', '111111', 'NOW', 12);
INSERT INTO TAB_BW ( COD, COD_ID, DESCRIPTION, AREA ) VALUES (
'05', '000001', 'GOOD BYE', 1234567.34234);
Now I'd like to create a CSV file with these data
I created this pl/sql stored procedure:
CREATE OR REPLACE procedure BW is
file_a sys.utl_file.file_type;
     file_l sys.utl_file.file_type;
DATA_ELAB varchar2(50);
MSG varchar2(200);
directory varchar2(50) := 'C:\EXTRACT';
file_name varchar2(50) := 'BW';
VAR_COD VARCHAR2(66);
VAR_COD_ID VARCHAR2(20);
VAR_DESCRIPTION VARCHAR2(64);
VAR_AREA VARCHAR2(64);
CURSOR CUR_IMM IS
SELECT COD,
COD_ID,
DESCRIPTION,
AREA
FROM TAB_BW;
PROCEDURE GET_DATA_DAY IS
begin
     SELECT to_char(SYSDATE,'Day dd Month yyyy * hh24:mi:ss')
INTO DATA_ELAB
FROM DUAL;
end GET_DATA_DAY;
PROCEDURE OPEN_FILE IS
BEGIN
file_a :=
sys.utl_file.fopen(directory,file_name||'_'||TO_CHAR(SYSDATE,'DD_MM_YYYY')||'.
csv','w');
END OPEN_FILE;
PROCEDURE CLOSE_FILE IS
BEGIN
sys.utl_file.fclose(file_a);
END CLOSE_FILE;
PROCEDURE NOT_FOUND IS
BEGIN
sys.utl_file.put_line(file_l,('DATA NOT FOUND'));
END NOT_FOUND;
PROCEDURE WRITE_DATA IS
BEGIN
sys.utl_file.put_line(file_a,VAR_COD||','||VAR_COD_ID||','||VAR_DESCRIPTION||'
,'||VAR_AREA);
END WRITE_DATA;
BEGIN
OPEN_FILE;
GET_DATA_DAY;
OPEN CUR_IMM;
IF (CUR_IMM%NOTFOUND)
THEN
NOT_FOUND;
ELSE
LOOP
FETCH CUR_IMM INTO VAR_COD,
VAR_COD_ID,
VAR_DESCRIPTION,
VAR_AREA;
EXIT WHEN (CUR_IMM%NOTFOUND);
WRITE_DATA;
END LOOP;
END IF;
CLOSE CUR_IMM;
GET_DATA_DAY;
CLOSE_FILE;
END BW;
but when I open the file BW.csv
I get these output:
COD......COD_ID...........DESCRIPTION...........AREA
00.......000099...........MY HOME...............21.654
01.......001234...........MY HOME...............MY DOG...........2111.3232
11.......033333...........OK....................NO................1222.22
03.......111111...........NOW....................12
05.......000001...........GOOD BYE...............1234567.34234
I'd like to get this output when I open the file BW.csv:
COD......COD_ID...........DESCRIPTION...........AREA
00.......000099...........MY HOME...............21.654
01.......001234...........MY HOME, MY DOG.......2,111.3232
11.......033333...........OK, NO................1,222.22
03.......111111...........NOW....................12
05.......000001...........GOOD BYE...............1,234,567.34234
How Can I modify my procedure to get this output?
Thanks in advance!

MY HOME and MY DOG
OK and NO
are in separated columns
I'd like to have it in same columnsEnclose the strings in double quotes
Something like
00.......000099..........."MY HOME"...............21.654Two more thing I just noticed:
- Some of your rows seems to have 5 columns instead of 4
- Excel is going to convert your Id to Numbers; 000 will be displayed as 99
By the way your format is just a fixed-length format but not a CSV-format.
CSV (comma separated values) would be something like
"COD";"COD_ID";"DESCRIPTION";"AREA"
"00";"000099";"MY HOME",21.654

Similar Messages

  • How to create a csv file with NCS attributes?

    Hi
    i installed Cisco Prime NCS and trying to perform bulk update of device credentials with csv file.
    How to create a csv file with all required attributes?
    This is part of NCS online help talking about this topic:
    Bulk Update Devices—To update the device credentials in a bulk, select Bulk Update Devices from the Select a command drop-down list. The Bulk Update Devices page appears.You can choose a CSV file.
    Note        The CSV file contains a list of devices to be updated, one device per line. Each line is a comma separated list of device attributes. The first line describes the attributes included. The IP address attribute is mandatory.
    Bellow is test csv file i created but does not work:
    10.64.160.31,v2c,2,10,snmpcomm,ssh,zeus,password,password,enablepwd,enablepwd,60
    10.64.160.31,v2c,2,10,snmpcomm,ssh,zeus,password,password,enablepwd,enablepwd,60
    The error i am getting while importing this file:
    Missing mandatory field [ip_address] on header line:10.64.160.31,v2c,2,10,snmpcomm,ssh,zeus,password,password,enablepwd,enablepwd,60
    Assistance appreciated.

    It looks like the IP address field is incorrectly set.,
    It should be as follows
    {Device IP},{Device Subnet Mask}, etc etc
    so a practical example of the aboove could be (i dont know if this is completely correct after the IP address / Subnet Mask)
    10.64.160.31,255.255.255.0,v2c,2,10,snmpcomm,ssh,zeus,password,password,enablepwd,enablepwd,60
    below is a link to the documentation
    http://www.cisco.com/en/US/docs/wireless/ncs/1.0/configuration/guide/ctrlcfg.html#wp1840245
    HTH
    Darren

  • How to write a CSV file in OSB

    Hi All,
    can any one tell me How to write a CSV file in OSB?
    Thanks.

    Hey, I couldnot find any xsl usage inside pipeline pair in the links given by you. Do you have any links that gives a sample example.I could not find any links with examples. I will send you a simple config jar demonstrating the use of XSLT resources/transformations.
    secondly should MFL doc replicate the name(s)of the nodes of the source xsd:I'm not sure If I understood your question.Can you please explain?
    Ex: My database schema looks like:
    <?xml version = '1.0' encoding = 'UTF-8'?>
    <xs:schema targetNamespace="http://xmlns.oracle.com/pcbpel/adapter/db/top/AssetsPoll" xmlns="http://xmlns.oracle.com/pcbpel/adapter/db/top/AssetsPoll" elementFormDefault="qualified" attributeFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="CountriesCollection" type="CountriesCollection"/>
    <xs:complexType name="CountriesCollection">
    <xs:sequence>
    <xs:element name="Countries" type="Countries" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
    </xs:complexType>
    <xs:complexType name="Countries">
    <xs:sequence>
    <xs:element name="countryId">
    <xs:simpleType>
    <xs:restriction base="xs:string">
    <xs:maxLength value="2"/>
    </xs:restriction>
    </xs:simpleType>
    </xs:element>
    <xs:element name="countryName" minOccurs="0" nillable="true">
    <xs:simpleType>
    <xs:restriction base="xs:string">
    <xs:maxLength value="40"/>
    </xs:restriction>
    </xs:simpleType>
    </xs:element>
    <xs:element name="regionId" type="xs:decimal" minOccurs="0" nillable="true"/>
    </xs:sequence>
    </xs:complexType>
    </xs:schema>
    and the corresponding MFL that I have created gives this output
    <?xml version="1.0" encoding="windows-1252"?>
    <countriesCollection1>
    <Countries>
    <counrtyId>counrtyId</counrtyId>
    <country_name>country_name</country_name>
    <regionId>regionId</regionId>
    </Countries>
    <Countries>
    <counrtyId>counrtyId</counrtyId>
    <country_name>country_name</country_name>
    <regionId>regionId</regionId>
    </Countries>
    </countriesCollection1>
    Why I am asking this beacuse there is an error that i am getting:
    Jun 19, 2009 5:50:50 PM IST> <Error> <JCATransport> <BEA-381951> <JCA inbound r
    quest only invocation failed, exception: java.security.PrivilegedActionExceptio
    : com.bea.wli.sb.transports.TransportException: Binary to XML mfl transformatio
    failed for the MFL Resource Database-Jms-File/Database-File/MFLSample : null
    ava.security.PrivilegedActionException: com.bea.wli.sb.transports.TransportExce
    tion: Binary to XML mfl transformation failed for the MFL Resource Database-Jms
    File/Database-File/MFLSample : null..................................................
    Any help?
    Regards
    PS

  • How to import an .csv file into the database?

    and can we code the program in JSP to import the.csv file into the database.

    It is better to use Java class to read the CSV file and store the contents in the database.
    You can use JSP to upload the CSV file to the server if you want, but don't use it to perform database operations.
    JSPs are good for displaying information on the front-end, and for displaying HTML forms, there are other technologies more suitable for the middle layer, back end and the database layer.
    So break you application into
    1) Front end - JSPs to display input html forms and to display data retrieved from the database.
    2) Middle layer - Servlets and JavaBeans to interact with JSPs. The code that reads the CSV file to parse it's contents should be a Java Class in the middle layer. It makes use of Java File I/O
    3) Database layer - Connects to the database using JDBC (Java Database Connectivity), and then writes to the database with SQL insert statements.
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Keeping the above concepts in mind, first build a simple JSP and get it to work,
    then research on Google , for Java File I/O , discover how to read a file,
    Then search on how to readh a CSV file using Java.
    After researching you should be able to read the CSV file line by line and store each line inside a Collection.
    Then research on Google, on how to write to the database using JDBC
    Write a simple program that inserts something to a dummy table in the database.
    Then, read the data stored in the Collection, and write insert statements for each records in the collection.

  • How to create a CSV file in java

    how to create a CSV file in java

    this is the code that I have used in a hp project:
    private static final String DELIMIT = ",";
    StringBuffer buf = new StringBuffer();
    public void addString(String str){
    buf.append(toEscapedStringLiteral(str.replaceAll(" ","").trim())).append(DELIMIT);
    public void sendFile( String strData ,
                                String strTitle,
                                String strContType,
                                HttpServletResponse res ) throws IOException {
              byte[] _filedata=strData.getBytes();
              res.setContentType( strContType );
              res.setHeader( "Content-Disposition", "attachment;filename="+ strTitle );     
                     DataOutputStream out = new DataOutputStream( res.getOutputStream() );
              out.write( _filedata, 0, _filedata.length );
              out.close();
    public void addStringWhithReturn(String str){
              buf.append(toEscapedStringLiteral(str.replaceAll(" ","").trim()));
              buf.append( "\n" );
    private String toEscapedStringLiteral( String charSeq ) {
              if ( null == charSeq ) {
                   charSeq = "";
              return "\"" + charSeq + "\"";
    ....hope its help
    kou

  • How to load 100 CSV file to DSO / InfoCube

    Hi
    How to load 100 CSV files of transcational data to DSO / InfoCube?

    Hi,
    you can achieve to write the .bat (batch file program in windows)
    .bat program it will convert to xsl to .CSV format.
    in process chain you can use the OS COMMAND option while creating process chain.
    it will first trigger the bat file then it will trigger the excel files and info package.
    now i am also working on same scenario now.
    please find the below doc how to create the process chain using os command.
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/e0c41c52-2638-2e10-0b89-ffa4e2f10ac0?QuickLink=index&…
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/3034bf3d-9dc4-2d10-9e93-d4ba01505ed9?QuickLink=index&…
    Thanks,
    Phani.

  • Help Me... How to get Data from CSV File...?

    Hi Everyone..!
    This is yajiv and am working in CS3 Photoshop platform. I know about Java Script. Is it possible to get the data from CSV files. Actually our client use to send us the CSV files which contains a lot of swatch name and reference files in one particular image name.
    Actually how we work on that CSV file is, first we copy file name to search that CSV file. then get the result to paste into layer name. This process continue till the end of swatch.
    Thank in Advance
    -yajiv

    > Is it possible to get the data from CSV files.
    Have you tried searching this forum?

  • How do I import csv file into a SharePoint list?

    I am trying to use a PowerShell script to load data into a SharePoint list from a csv file. When I run my code, it seems to go through the process of loading the data into the list. However when I go to my list, all I see is "System.Object[]" displayed
    in the first column of all my rows with no other data displayed. When I check my csv file, I see a ton of data (several rows and columns) but that is not being moved to my SharePoint list. This is what my script looks like
    if((Get-PSSnapin | Where {$_.Name -eq “Microsoft.SharePoint.PowerShell”}) -eq $null) {
    Add-PSSnapin Microsoft.SharePoint.PowerShell
    $web = Get-SPWeb http://link to web
    $list = $web.lists["List Name"]
    $recordsNumber = 0
    foreach($i in Import-CSV myCSVFile.csv)
    $new = $list.Items.Add()
    $new["Title"] = $i.Title,
    $new["FirstName"] = $i.FirstName,
    $new["LastName"] = $i.LastName
    $new.Update()
    $recordsNumber++
    "Added " + $recordsNumber.ToString() + " records."
    "Done. Press any key to continue..."
    $null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
    Any ideas on how to fix this, and get my list populated with data?

    if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )
    Add-PsSnapin Microsoft.SharePoint.PowerShell
    $host.Runspace.ThreadOptions = "ReuseThread"
    #Open SharePoint List
    $SPServer=http://SOMESERVER
    $SPAppList="/Lists/List Name/"
    $spWeb = Get-SPWeb $SPServer
    $spData = $spWeb.GetList($SPAppList)
    $InvFile="myCSVFile.csv"
    # Get Data from Inventory CSV File
    $FileExists = (Test-Path $InvFile -PathType Leaf)
    if ($FileExists) {
    "Loading $InvFile for processing..."
    $tblData = Import-CSV $InvFile
    } else {
    "$InvFile not found - stopping import!"
    exit
    # Loop through Applications add each one to SharePoint
    "Uploading data to SharePoint...."
    foreach ($row in $tblData)
    "Adding entry for "+$row."Application Name".ToString()
    $spItem = $spData.AddItem()
    $spItem["Title"] = $row."Title".ToString()
    $spItem["FirstName"] = $row."FirstName".ToString()
    $spItem["LastName"] = $row."LastName".ToString()
    $spItem.Update()
    "Upload Complete"
    $spWeb.Dispose()
    Link
    Please 'propose as answer' if it helped you, also 'vote helpful' if you like this reply.

  • How to upload multiple .CSV files in the same time.

    Hi Legends,
    Can anyone please help me to resolve my issue?
    This is very urgent and critical.
    Description:
    We have two users.1)edw_user_dump
    2)prd_udm.
    We need to upload the xx.csv file at the same time for these two users in oracle forms.
    we have differentiated .csv file name based on the user names.
    the main problem is in the sql loader command the xx.csv file name is created but the data is not captured in the server (kentucky) .
    Below is my code for the upload.
    -- To delete the Part_Mast.log file from the client
    DECLARE
    pid WEBUTIL_HOST.PROCESS_ID;
    v_result PLS_INTEGER;
    v_username varchar2(30) := GET_APPLICATION_PROPERTY(USERNAME);
    BEGIN
    v_result := WEBUTIL_HOST.Get_return_Code(pid ) ;
    host('cat /dev/null > /tmp/'||v_username||'_'||'EDW_CF_IO_UPLOAD.log');
    host('cat /dev/null > /tmp/'||v_username||'_'||'"CF615 IO Upload.csv"');
    END;
    DECLARE
    l_success boolean:=FALSE;
    l_bare_filename varchar2(100):=NULL;
    v_username varchar2(30) := GET_APPLICATION_PROPERTY(USERNAME);
    BEGIN
    -- Delete the content of the log and bad file
    host('cat /dev/null > /tmp/'||v_username||'_'||'EDW_CF_IO_UPLOAD.log');
    --host('cat /dev/null > /tmp/Part_Mast.bad');
    -- Upload the data file to Application Server
    l_bare_filename := v_username||'_'||substr(:FIC_SOURCE,instr(:FIC_SOURCE,'\',-1)+1);
    l_success := webutil_file_transfer.Client_To_AS_with_progress
    (clientFile => :FIC_SOURCE
    ,serverFile => '/tmp/'||l_bare_filename
    ,progressTitle => 'Upload to Application Server in progress'
    ,progressSubTitle => 'Please wait'
    ,asynchronous => false
    ,callbackTrigger => null
    IF l_success THEN
    NULL;
    ELSE
    null;
    END IF;
    EXCEPTION
    WHEN OTHERS THEN
    RAISE Form_Trigger_Failure;
    END;
    DECLARE
    v_username varchar2(30) := GET_APPLICATION_PROPERTY(USERNAME);
    begin
    host('cat /dev/null > /tmp/'||v_username||'_'||'EDW_CF_IO_UPLOAD.log');
    host('cat /dev/null > /tmp/EDW_CF_IO_UPLOAD.bad');
    end;
    BEGIN
    DECLARE
    v_username varchar2(30) := GET_APPLICATION_PROPERTY(USERNAME);
    v_password varchar2(30) := GET_APPLICATION_PROPERTY(PASSWORD);
    v_connect_string varchar2(30) := GET_APPLICATION_PROPERTY(CONNECT_STRING);
    a_host varchar2(500);
    BEGIN
    a_host :='/tmp/'||v_username||'_'||'"CF615 IO Upload.csv"';
    host('sqlldr '||v_username||'/'||v_password||'@'||v_connect_string||' '|| 'control=/home/edw_bis/ctl/GLB_CF_IO_UPLOAD.CTL'||' '|| 'DATA=a_host'||' '|| 'LOG=/tmp/'||v_username||'_'||'EDW_CF_IO_UPLOAD.log SKIP=1 errors=200000 DIRECT=FALSE');
    dbms_output.put_line(a_host);
    END;
    DECLARE
    v_username varchar2(30) := GET_APPLICATION_PROPERTY(USERNAME);
    begin
    host('cat /dev/null > /tmp/'||v_username||'_'||'"CF615 IO Upload.csv"');
    EXCEPTION
    WHEN OTHERS THEN
    RAISE Form_Trigger_Failure;
    END;
    end;
    DECLARE
    al_id3 ALERT;
    al_button Number;
    BEGIN
    edw_user_dump.SANM_PRC_MERGE_CF_IO_UPLOAD(:global.v_plsql_res,:global.v_ins_rec,:global.v_upd_rec);
    IF NVL(:global.v_plsql_res,0) = 0 and (:global.v_ins_rec !=0 OR :global.v_upd_rec != 0 ) then
    al_id3 :=FIND_ALERT('ROWINS');
    SET_ALERT_PROPERTY(al_id3,alert_message_text,' Process Completed Successfully!'||CHR(10)||' Rows Inserted : '||:global.v_ins_rec ||CHR(10)||' Rows Updated : '||:global.v_upd_rec);
    al_button := SHOW_ALERT( al_id3 );
    ELSIF (:global.v_plsql_res IN(-1,0) or :global.v_plsql_res > 0) and (:global.v_ins_rec =0 and :global.v_upd_rec = 0 and :global.v_del_rec =0 ) then
    al_id3 :=FIND_ALERT('ROWINS');
    SET_ALERT_PROPERTY(al_id3,alert_message_text,' Process Failed. Please Download the Log File '||CHR(10)||' Rows Failed : '||:global.v_plsql_res||CHR(10)||' Rows Inserted : '||:global.v_ins_rec ||CHR(10)||' Rows Updated : '||:global.v_upd_rec);
    al_button := SHOW_ALERT( al_id3 );
    ELSE
    al_id3 :=FIND_ALERT('ROWINS');
    SET_ALERT_PROPERTY(al_id3,alert_message_text,'Please Download the Log File '||CHR(10)||' Rows Failed : '||:global.v_plsql_res||CHR(10)||' Rows Inserted : '||:global.v_ins_rec ||CHR(10)||' Rows Updated : '||:global.v_upd_rec );
    al_button := SHOW_ALERT( al_id3 );
    END IF;
    EXCEPTION WHEN OTHERS THEN
    RAISE Form_Trigger_Failure;
    END;
    DECLARE
    v_username varchar2(30) := GET_APPLICATION_PROPERTY(USERNAME);
    begin
    host('cat /dev/null > /tmp/'||v_username||'_'||'"CF615 IO Upload.csv"');
    host('rm -rf /tmp/'||v_username||'_'||'"CF615 IO Upload.csv"');
    end;
    Thanks in advance!
    Thanks,
    Madhusudhanan

    Madhusudhanan,
    A couple of observations. First; always list your exact Forms version (eg; 10.1.2.0.2 not 10g R2). In most cases, the solution is different depending on the Forms version. Second; why must you use Forms to kick off a SQL Loader process? This is a server-side process and should be initiated by a server side process. If you absolutely must use Forms to kick off the process, again we need your Forms version in order to offer any solutions. Based on your code sample, I can asusme you are at least using Forms 9i becuase you are using WebUtil.
    Is your Database and Application Server the same physical computer? If they are not, this would explain why your HOST command isn't working because HOST runs against the Application Server not the Database server.
    Third; have you considered using and External Table (if your RDBMS version supports them) for each of the files you are attempting to upload? In this instance, it would be helpful to know your RDBMS version as well. External Tables can be a little frustrating to set up the first time, but as with any new construct you use - it gets easier the more you use it.
    Fourth; are you getting any errors in your log file(s)? If so, what are the errors? Please list the full error message if you have one.
    Finally, with respects to your statement:
    Posted: Mar 18, 2011 2:30 PM - Madhu This is very urgent and critical.>
    You have to understand that forum contributers are all volunteers - this is not our full-time job. If your issue is truely urgent I suggest you open a Service Request (SR) with Oracle Support! ;-)
    Craig B-)
    If someone's response is helpful or correct, please mark it accordingly.

  • How to read/write .CSV file into CLOB column in a table of Oracle 10g

    I have a requirement which is nothing but a table has two column
    create table emp_data (empid number, report clob)
    Here REPORT column is CLOB data type which used to load the data from the .csv file.
    The requirement here is
    1) How to load data from .CSV file into CLOB column along with empid using DBMS_lob utility
    2) How to read report columns which should return all the columns present in the .CSV file (dynamically because every csv file may have different number of columns) along with the primariy key empid).
    eg: empid report_field1 report_field2
    1 x y
    Any help would be appreciated.

    If I understand you right, you want each row in your table to contain an emp_id and the complete text of a multi-record .csv file.
    It's not clear how you relate emp_id to the appropriate file to be read. Is the emp_id stored in the csv file?
    To read the file, you can use functions from [UTL_FILE|http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/u_file.htm#BABGGEDF] (as long as the file is in a directory accessible to the Oracle server):
    declare
        lt_report_clob CLOB;
        l_max_line_length integer := 1024;   -- set as high as the longest line in your file
        l_infile UTL_FILE.file_type;
        l_buffer varchar2(1024);
        l_emp_id report_table.emp_id%type := 123; -- not clear where emp_id comes from
        l_filename varchar2(200) := 'my_file_name.csv';   -- get this from somewhere
    begin
       -- open the file; we assume an Oracle directory has already been created
        l_infile := utl_file.fopen('CSV_DIRECTORY', l_filename, 'r', l_max_line_length);
        -- initialise the empty clob
        dbms_lob.createtemporary(lt_report_clob, TRUE, DBMS_LOB.session);
        loop
          begin
             utl_file.get_line(l_infile, l_buffer);
             dbms_lob.append(lt_report_clob, l_buffer);
          exception
             when no_data_found then
                 exit;
          end;
        end loop;
        insert into report_table (emp_id, report)
        values (l_emp_id, lt_report_clob);
        -- free the temporary lob
        dbms_lob.freetemporary(lt_report_clob);
       -- close the file
       UTL_FILE.fclose(l_infile);
    end;This simple line-by-line approach is easy to understand, and gives you an opportunity (if you want) to take each line in the file and transform it (for example, you could transform it into a nested table, or into XML). However it can be rather slow if there are many records in the csv file - the lob_append operation is not particularly efficient. I was able to improve the efficiency by caching the lines in a VARCHAR2 up to a maximum cache size, and only then appending to the LOB - see [three posts on my blog|http://preferisco.blogspot.com/search/label/lob].
    There is at least one other possibility:
    - you could use [DBMS_LOB.loadclobfromfile|http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_lob.htm#i998978]. I've not tried this before myself, but I think the procedure is described [here in the 9i docs|http://download.oracle.com/docs/cd/B10501_01/appdev.920/a96591/adl12bfl.htm#879711]. This is likely to be faster than UTL_FILE (because it is all happening in the underlying DBMS_LOB package, possibly in a native way).
    That's all for now. I haven't yet answered your question on how to report data back out of the CLOB. I would like to know how you associate employees with files; what happens if there is > 1 file per employee, etc.
    HTH
    Regards Nigel
    Edited by: nthomas on Mar 2, 2009 11:22 AM - don't forget to fclose the file...

  • How to graph a CSV file in VB

    Hi, so I have a CSV file in my working directory and dont know how to load in into a graph in VB. I already loaded my chart into the form and its called "Chart1" with "Series1".
    The CSV has the following structure:
    Date Value1 Value2
    27/04/2012 45.1 60.1
    26/04/2012 45.2 60.2.. ..
    I cant figure out how to extract this data from the "*.csv" file and put in it a graph where the
    Date is the x axis and the
    Value2 is the y axis.
    Any code would be greatly appreciated!

    Is the CSV file data in reverse date order?  Your example includes only two lines, so the sequence is not clear.
    If so, then you want to add the items to the series by working from the end of the file towards the beginning of the file. That would plot the points along the x-axis in order of increasing date.  Is that correct?
    But then you say that you want to plot from the beginning to a certain date. Do you mean that you want to plot (reversed) from the beginning of the file to a certain nominated ending date? Or do you want to plot the items starting at the end of the file
    and working backwards through the file so that the plot starts at a nominated starting date?  I have assumed the former.
    To adjust the above code for these new requirements you should load the data into an object that you can manipulate to your requirements.  Then you need to separate the plotting from the file access.  A list is more suitable than an array.
    Dim Readings As List(Of Reading) = New List(Of Reading)
    Dim StartDate As Date = New Date(2012, 4, 24)
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim CurrentPoint As Integer = 0
    Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser("C:\Users\Public\Readings.txt")
    MyReader.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited
    MyReader.Delimiters = New String() {","}
    Dim currentRow As String()
    While Not MyReader.EndOfData
    Try
    currentRow = MyReader.ReadFields()
    Dim D As String = currentRow(0)
    Try
    Dim Y As Double = CDbl(currentRow(2))
    Readings.Add(New Reading(D, Y))
    Catch ex As InvalidCastException
    If CurrentPoint <> 0 Then
    MsgBox("Item " & currentRow(2) & " is invalid. Skipping")
    End If
    End Try
    Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
    If CurrentPoint <> 0 Then
    MsgBox("Line " & ex.Message & " is invalid. Skipping")
    End If
    End Try
    End While
    End Using
    Readings.Reverse()
    CurrentPoint = 0
    Chart1.Series(0).Points.Clear()
    For Each R As Reading In Readings
    Dim D As Date = CDate(R.Read_Date)
    If D >= StartDate Then
    Chart1.Series(0).Points.AddY(R.Read_Data)
    Chart1.Series(0).Points(CurrentPoint).AxisLabel = R.Read_Date
    CurrentPoint += 1
    End If
    Next
    End Sub
    That code uses the following class:
    Public Class Reading
    Public Read_Date As String
    Public Read_data As Double
    Public Sub New(ByVal Item1 As String, ByVal item2 As Double)
    Read_Date = Item1
    Read_data = item2
    End Sub
    End Class
    I know this thread is a couple years old but I tried this code and it works in Studio 2013 Community and it is very close to what I need. I want to make it a line chart and I want to have 4 series- Temp, Temp_SP, RH% and RH%_SP so I can log some trending
    data from an environmental chamber at work. Can someone help me out with this?
    Thanks,
    Dan

  • How to loop through CSV file

    Hi,
    I want to loop through each column of a CSV file.
    And while looping each column, I want to loop each row
    starting with the 2st row.
    I wrote the code as below, but it is looping through the rows
    starting from row 1.
    How do I make it start the loop as from row 2 in the CSV ?
    (see code below)
    Can someone tell me how to do this?
    Thx
    <!--- get and read the CSV-TXT file --->
    <cffile action="read" file="C:\Documents and
    Settings\user\Desktop\EM-CSV\test.csv" variable="csvfile">
    <!--- loop through the CSV-TXT file on line breaks and
    insert into database --->
    <table border="1">
    <cfloop index="index" list="#csvfile#"
    delimiters="#chr(10)##chr(13)#">
    <!--- <cfoutput>#listgetAt('#index#',1,
    ',')#</cfoutput><br> --->
    <tr>
    <td><cfoutput>#index#</cfoutput></td>
    <td><cfoutput>#listgetAt('#index#',2,
    ',')#</cfoutput></td>
    <td><cfoutput>#listgetAt('#index#',3,
    ',')#</cfoutput></td>
    </tr>
    </cfloop>
    </table>

    Hello, your code works perfectly.
    Now I am having a slight problem with it.
    I have added the code to check whether a particular cell of
    the CSV is blank. (see code below)
    But it is giving me error message.
    Can you please tell me what am doing wrong?
    Thx
    <!--- loop through the CSV-TXT file on line breaks and
    insert into database --->
    <cfset isRowTwoOrLater=false>
    <table border="1">
    <cfloop index="row" list="#csvfile#"
    delimiters="#chr(10)##chr(13)#">
    <cfif isRowTwoOrLater>
    <tr>
    <cfif #listgetAt(row,1, ',')# neq ''> <!--- I HAVE
    ADDED THIS PART TO CHECK WHETHER IT IS BLANK --->
    <td><cfoutput>#listgetAt(row,1,
    ',')#</cfoutput></td>
    <cfelse>
    <td><cfoutput>It is
    blank</cfoutput></td>
    </cfif>
    <td><cfoutput>#listgetAt(row,2,
    ',')#</cfoutput></td>
    <td><cfoutput>#listgetAt(row,3,
    ',')#</cfoutput></td>
    </tr>
    <cfelse>
    <cfset isRowTwoOrLater = true>
    </cfif>
    </cfloop>
    </table>

  • How to search a .csv file for data using its timestamp, then import to labview

    Hi, I'm currently obtaining density, viscosity and temperature data from an instrument, adding a timestamp and writing it to a .csv file which I can view in Excel. This works fine (see attached code) but what I need to do now is to search that csv file for data which was obtained at a certain time, import the temperature, density & viscosity values at this time back into Labview to do some calculations with them, while the data acquisition process is still ongoing.
    I've found various examples on how to import an entire csv file into labview, but none on how to extract data at a specific time. Also, whenever I try to do anything with the .csv file while my data acquistion VI is running, I receive error messages (presumably because I'm trying to write to and import data from the .csv file simultaneously). Is there some way around this, maybe using case structures?
    If you need to know my skill level, I've been using Labview for a few weeks and prior to that have basically no experience of writing code, so any help would be great. Thanks!
    Solved!
    Go to Solution.
    Attachments:
    Lemis VDC-30 read registers MODBUS v5.vi ‏56 KB

    It sounds as if you are going about this a little backwards writing to a data file and then extracting from the file but its the weekend so I can't think of an improved way to do it at the moment. 
    Searching for a specific time with those specific values is quite easy, or if you wanted to select any time then you could interpolate the values to find any value that you want (This is where the contiguous measurement comes in, as you have readings at discrete times you will have to interpolate the values if you want to get the 'measured value' at a time point that is not exactly one of your measured points).
    If you can extract the TDMS time column and the T, D & V then simply thresholding and interpolating each of your array/data sets should allow readings at your desired times.
    Attachments:
    Interpolate.png ‏301 KB

  • How to download a CSV file to a shared network folder ?

    Hi Experts,
    I have created a report which exports a CSV file on application server using scheduled background job. I have used the OPEN DATASET feature to download the file on a location on the application server which is working fine.
    But my requirement is that I have to download this file to a shared folder which is situated on another location and is shared in my application server as 'N' drive. But when I give the path of this N drive in my report, its giving runtime error that the <filename> is not open.
    So pls help me how to give path to such shared network folder to download the file?
    Thanks,
    Vishal .

    Hi Guys,
    I tried alot but it didnt work.
    SO I decided to export the file on the application server only.
    I created a background job that runs periodically and exports the file to C drive of the application server.
    The job run sucessfully only the first time but gets cancelled after that.
    I ran the job for an hour but not a single time it finished successfully. Every time it was cancel with dump error shown below.
    +++++++++++++++++++++++++++++++++++++++++++
    Category               ABAP Programming Error
    Runtime Errors         DATASET_NOT_OPEN
    Except.                CX_SY_FILE_OPEN_MODE
    ABAP Program           ZBATCHSTOCK
    Application Component  Not Assigned
    Date and Time          01.08.2014 18:52:13
    Short text
         File "C:\GOOGLE_SAP\BATCH_DETAILS.CSV" is not open.
    What happened?
         Error in the ABAP Application Program
         The current ABAP program "ZBATCHSTOCK" had to be terminated because it has
         come across a statement that unfortunately cannot be executed.
    What can you do?
         Note down which actions and inputs caused the error.
         To process the problem further, contact you SAP system
         administrator.
         Using Transaction ST22 for ABAP Dump Analysis, you can look
         at and manage termination messages, and you can also
         keep them for a long time.
    ++++++++++++++++++++++++++++++++++++++++++++++++++++++
    And the same background job runs properly on development server without any cancelled job.
    So pls help me what should be the problem ??
    Thanks,
    Vishal

  • How to read a .CSV file using UTL_FILE

    HI,
    How do i read a .csv file line by line using UTL_FILE?
    Thanks in advance
    Regards,
    Gayatri

    ----do open the file logic
    begin
    ----Let's say this file is delimited by ','
    ---declare variables
    v_startPos number; -- starting position of field
    v_Pos number; -- position of string
    v_lenString number; -- length
    v_first_field varchar2(30);
    v_second_field varchar2(30);
    v_third_field varchar2(30);
    v_fourth_field varchar2(30);
    input_String varchar2(1000); -- buffer for each line of file
    ----Say you have a 4 column file delimited by ','
    delimitChar varchar2(1) := ','
    Joe;Joan;People;Animal
    Teddy;Bear;Beans;Toys
    begin
    loop
    utl_file.get_line(input_file, input_String); -- get each line
    ---- this will get the first field as specified by the last number
    v_Pos := instr(input_String,delChar,1,1);
    v_lenString := v_Pos - 1;
    v_first_field := substr(input_String,1,v_lenString);
    v_startPos := v_Pos + 1;
    -- this will get the second field
    v_Pos := instr(inString,delChar,1,2);
    v_lenString := v_Pos - v_startPos;
    v_second_field := substr(input_String,v_startPos,v_lenString);
    v_startPos := v_Pos + 1;
    -- 3rd field
    v_Pos := instr(inString,delChar,1,3);
    v_lenString := v_Pos - v_startPos;
    v_third_field := substr(input_String,v_startPos,v_lenString);
    v_startPos := v_Pos + 1;
    -- last field -- there is no delimiter for last field
    v_Pos := length(input_String) + 1;
    v_lenString := v_Pos - v_startPos;
    v_fourth_field := substr(input_String,v_StartPos,v_lenString);
    end;
    EXCEPTION
    WHEN no_data_found then
              fnd_file.put_line(FND_FILE.LOG, 'Last line so exit');
              exit;
    end loop;

Maybe you are looking for

  • Can't install or uninstall the latest version of iTunes

    Everytime I go to install the latest version of iTunes I get through most of it, then a window comes up that says "Windows Installer" - "The feature you are trying to use is on a network resource that is unavailable." - "Click OK to try again, or ent

  • Steps for down payment to vendor

    Hi SAPians, Can anyone throw some light on the steps to configure downpayments to vendors with T.Codes. I have no idea about this. Thanks in advance. Vijay

  • A Performance Issue

    Hello Oracle Gurus, I have met a performance issue as below, can anyone help me figure out how to improve it? Database Versoin: 10.2.0.4.0 Table: non_fin_hist, a partitioned table by range on trxn_dt, each partition include data of one year. Index: t

  • Material Ledger Check

    I have few questions regarding ML. We have ML in place since long time, and now are planning to consider expenses that need to be picked in ML 1)Currently we have Valuation Area as ML active. We are planning to have new Accounts that need to be pulle

  • HT4623 Getting kicked off an App

    Help! When i am on an App on my Ipad there are many times when I get kicked off and the screen on the ipad goes to the home screen. This is rediculice! What can I do???