Need help in writing data to a flat file in .csv format

Hi All,
could you please show with a sample example to write data in .csv format using UTL_file.
The result of the refcursor i want to write to a file in .csv format.
How can i achieve this.
Thx

Hi,
There are two ways to acheive this.
First and which I prefer is creating a SQL script which will generate csv file at the specified location in CSV format. And then this SQL script can be called from your cron job similar to how you call stored procedure. Following is pseudo code that can be used -
set linesize 500
set echo off
set feedback off
set prompt off
set pagesize 0
spool <name of the csv file>.csv
<Your select statement>;
spool offPut select statement delimiting columns you want to use with ','. E.g. following query should create a CSV file named as abc.csv with one record and 2 columns delimited by comma. First column is ENO and second column is ENAME.
set linesize 500
set echo off
set feedback off
set prompt off
set pagesize 0
spool abc.csv
select ENO || ',' || ENAME from employee;
spool offSecond, you can write a PLSQL procedure and then call this procedure from cron job. There is a generic procedure shared by BluShadow some time back which is a very good example for this. Please refer to following link for this solution -
REF Cursor creating CSV files
I will suggest to use first method above if possible since it will be faster and less complicated in my opinion. Second method is recommended for scenarios where select statement is created dynamically and cannot be written during development.
Hope this solves your purpose.
Cheers,
Anirudha

Similar Messages

  • Need help ASAP with Data Flow Task Flat File Connection

    Hey there,
    I have a Data Flow Task within a ForEach loop container.  The source of the flow is ADO.NET connection and the destination is a Flat File Connection.  I loop through a collection of strings in the ForEach loop.  Based on the string content,
    I write some data to the same destination file in each iteration overwriting the previous version. 
    I am running into following Errors:
    [Flat File Destination [38]] Warning: The process cannot access the file because it is being used by another process.
    [Flat File Destination [38]] Error: Cannot open the datafile "Example.csv".
    [SSIS.Pipeline] Error: Flat File Destination failed the pre-execute phase and returned error code 0xC020200E.
    I know what's happening but I don't know how to fix it.  The first time through the ForEach loop, the destination file is updated.  The second time is when this error pops up.  I think it's because the first iteration is not closing the destination
    file. How do I force a close of the file within Data Flow task or through a subsequent Script Task.
    This works within a SQL 2008 package on one server but not within SQL 2012 package on a different server.
    Any help is greatly appreciated.
    Thanks! 

    Thanks for the response Narsimha.  What do you mean by FELC? 
    First time poster - what is the best way to show the package here?

  • Converting flat files to csv format

    hi,
    Iam converting flat files to csv format..the problem is that iam running a script for inserting values.while i run this script it works fine .but while i open this csv file the datas in the excel sheet is not coming in a single line that is for a particular record its moving to second line .there is a break for a single record.so there is a problem in conversion.can anything be done in it this to avoid the breaking of lines
    thanks
    Ratheesh

    YOGenereally, you shouldn't convert from a lossy format AAC or MP3) to another lossy fomrat.
    It's called loss because you lose information when you convert it.
    If you only use these files on the computer and the iPod, I'd recommend AAC. Better quality at same bit rate as MP3.

  • Need help in writing data from JSP to excel

    Hi ,
    I need help in writing the data from JSP to excel.I somehow able to retrieve the data into excel but unable to get the required format.
    For eg: The amount should be displayed in 0.00 format .when i am exporting it to excel it is displaying as 0 :( .
    I am using the following code in JSP.
    "out.print(amt + '\t');"
    Would like to know if there is any otherway where in i can get my requirement.
    Thanks
    Tom

    Hi,
    Try using format part of the JSTL tag libs.
    Syntax :
    <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
    <fmt:formatNumber value="40" pattern="$#,##0.00"/>
    I need help in writing the data from JSP to excel.I
    somehow able to retrieve the data into excelHow do u convert the jsp to excel?
    One way to convert the jsp page to excel, is to render it as an excel appl instead of html. Set the content type of the response to application/ms-excel.
    response.setContentType("application/ms-excel")Hope this Helps....

  • Error writing data in a flat file using UTL_FILE feature

    Hi All,
    I have written a package which fetches data from four different cursors and inserts into a temporary table.
    Now this temporary table is used to write data in a file using the UTL_FILE feature.
    fhandler :=
    UTL_FILE.fopen (l_path,'Demand_Transactions_'
    || TO_CHAR (SYSDATE, 'YYYYMMDDHH24MI')
    || '.txt',
    'w',
    max_linesize => 32767
    This table has 62593 records and when it starts writing data into the file from the table it errors out after writing 30045 records with the error - ORA-01722: invalid number.
    Can anyome please advise me is it because of the max_linesize => 32767. If not then what can be the possible reason.
    Any help in this would be highly appreciated.
    Regards,
    Shruti

    891330 wrote:
    Hi All,
    I have written a package which fetches data from four different cursors and inserts into a temporary table.
    Now this temporary table is used to write data in a file using the UTL_FILE feature.
    fhandler :=
    UTL_FILE.fopen (l_path,'Demand_Transactions_'
    || TO_CHAR (SYSDATE, 'YYYYMMDDHH24MI')
    || '.txt',
    'w',
    max_linesize => 32767
    This table has 62593 records and when it starts writing data into the file from the table it errors out after writing 30045 records with the error - ORA-01722: invalid number.
    Can anyome please advise me is it because of the max_linesize => 32767. If not then what can be the possible reason.Max linesize is the number of characters in a line before a newline has to be issued, not the number of rows written.
    The error would indicate that you have a character to number conversion going on somewhere but the characters are not numeric so it's failing that conversion.
    This doesn't sound like a UTL_FILE issue, but more to do with how you are building up your strings to output to the file.
    You would need to show us your code that builds up the lines you are writing out, with details of the datatypes of any of the columns/variables included in that.

  • Need help to replace hexadcimal character in flat file

    Hi,
    I am loading data from flat file.
    My flat file contains some hexadecimal characters.
    Hence when I load the data the load fails.
    I have checked many routines on SDN but could not get exact solution.
    Actually in some of my fields TAB or CARRIAGE RETURN symbols are coming.
    I want to write a simple routine in start routine of transfer structure. It will be # in PSA if I load the data till PSA.
    can anyone help me?
    Thanks & Regards,
    Rashmi.

    hi Rashmi,
    validate the data in flat file itself else you can edit the data in PSA while loading else you can allow the data is RSKC by specifying ALL_CAPITAL and execute .
    Assign Point if useful
    Ramesh

  • Please, I need help - How can I generate a text file with Word format?

    Hello friends at www.oracle.com ,
    is it possible for me to create a text file - that is, with TEXT_IO.fopen, and so on - that's already formatted as a Word document?
    We have a Forms program here, where it's needed to generate a text file with .RTF format, 8 centimeters margin, Times New Roman font, with size 7.
    Best regards,
    Franklin Goncalves Jr.

    Hello Shay,
    sincere thanks for your answer. And, to answer your last question, I'm using client-server model.
    Since I couldn't create this .RTF file by using built-ins like TEXT_IO, I tried to generate an .RTF file using Reports, passing the parameters DESTYPE, DESNAME and DESFORMAT, as shown below.
    add_parameter (pl_id, 'DESTYPE', text_parameter, 'FILE');
    add_parameter (pl_id, 'DESNAME', text_parameter, 'c:\franklin.rtf');
    add_parameter (pl_id, 'DESFORMAT', text_parameter, 'RTF');
    However, the just generated .RTF file is uncomprehensible. After opening the file at Microsoft Word, I can see the following message at the top of file:
    This file was created by Oracle Reports. Please view this document in Page Layout mode.
    ... and informations doesn't appear as desired.
    If I can't generate such text format by using TEXT_IO, and if generating an .RTF file through Reports shows me an incomprehensible result, how can I export the selected result to an .RTF file?
    When Reports is opened, choosing Generate to file -> RTF doesn't export anything.
    Thanks, and best regards,
    Franklin Goncalves Jr.

  • Need help pass in date parameter into bat file.

    Is it possible to schedule sql job to execute bat files and pass in date below.
    I want to take a system date and pass into the bat file below.  A Schedule Job will run on Monday at 9 P.M.
    I want to automate this process instead manually enter into the bat file.  Is that possible?
    Any suggestions is appreciate.  SQL 2012
    Thank you so much in advance.
    SQL Schedule job
    DECLARE @sMonday VARCHAR(25) = REPLACE(CONVERT(VARCHAR(10), GETDATE(), 1), '/', '')
    SET @sMonday = @sMonday + '_qa48_Clonedb'
    SELECT @sMonday
    --021315_qa48_Clonedb
    DECLARE @sPrevMonday VARCHAR(25) = CAST(REPLACE(CONVERT(CHAR(10), DATEADD(DAY, - (DATEPART(dw, GETDATE() ) - 1), GETDATE() ),1), '/', '') AS CHAR(6))
    SET @sPrevMonday= @sPrevMonday + '_qa48_Clonedb'
    SELECT @sPrevMonday
    --020815_qa48_Clonedb
    Result want:
    -- Testbatfile.bat
    REM 021615_qa48_Clonedb
    SET sToday = @sMonday        
    SET sPreviousWeek = @sPrevMonday
    SET sNumOfDay=07
    DiskMirror -l snapsrvcfdba n4brec01a -i privkey.ppk "snap rename sql32oltp_repl_dataf sqlsnap__brpRMSDVS050a__recent %sToday% "
    DiskMirror -l snapsrvcfdba n4brec01a -i privkey.ppk "snap rename sql32oltp_repl_logf  sqlsnap__brpRMSDVS050a__recent %sToday% "
    DiskMirror -l snapsrvcfdba l9ABC01d -i privkey.ppk "snap rename sql100oltp_repl_dataf %sPreviousWeek% sqlsnap__ABCPWSCVR050a__%sNumOfDay% "

    See
    https://sharminjahan625.wordpress.com/2013/08/30/384/
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Delete data from a flat file using PL/SQL -- Please help.. urgent

    Hi All,
    We are writing data to a flat file using Text_IO.Put_Line command. We want to delete data / record from that file after data is written onto it.
    Please let us know if this is possible.
    Thanks in advance.
    Vaishali

    There's nothing in UTL_FILE to do this, so your options are either to write a Java stored procedure to do it or to use whatever mechanism the host operating system supports for editing files.
    Alternatively, you could write a PL/SQL procedure to read each line in from the file and then write them out to a second file, discarding the line you don't want along the way.

  • Problem while writing to fixed length flat file from xml

    Hi,
    I have a problem in writing data into a flat file of fixed length...
    My input is a xml file and i want the output as a flat file. I am successful in converting the xml into flat file... But the main problem is, i am unable to insert spaces in between my fields in the flat file.
    The data in the flat file comes without spaces... Any suggestions on writing the schema...
    Regards
    Surya.

    Have a look at this doc
    http://otndnld.oracle.co.jp/document/products/as10g/101310/doc_cd/integrate.1013/b28994/nfb.htm#BGBBAJFD
    your element should be something like this, it pads with a space using the paddedBy expression
    <xsd:element name="C1" type="xsd:string" nxsd:style="fixedLength" nxsd:length="4" nxsd:paddedBy=" " nxsd:padStyle="tail" />if having trouble post what you want the file to look like, and the xsd you are using.
    cheers
    James

  • Need help for writing extract program

    hi
    i need help for writing extract program to retriew data from legacy system.
    i already developed bdc programs for me31k and me21.
    my requirement is to write extract program s for those t.codes.
    to retriew data from legacy system and stored in flat file.

    i need help with a java program. it is a program that allows the user to enter a student's GPA, number of extracurricular activities, and number of service activities. The user can not enter a gpa above 4.0 or below 0. The user can not enter a negative number for the number of both activities. If the student meets the following criteria: 1) GPA of 3.8 or above and at least one extracurricular activity and one service activity, 2) GPA below 3.8 but at least 3.4 and a total of at least three extracurricular and service activities, 3) GPA below 3.4 but at least 3.0 and at least two extracurricular activities and three service activities, the message "Scholarship candidate" should display. If the student does not meet the criteria above, then the message"not a candidate" should display. Can you help me, please?
    You haven't posted ANY 'java program' for us to help with.
    The forum is NOT a coding service. It is to help you with YOUR code.
    Post the code you have written and SHOW us (don't just tell us) how you compile it and execute it and the results you get. Then we can help you with any problems you are are having.
    If you need help understanding just what the program should be doing you need to ask your instructor to clarify the assignment.

  • Need help in transfering data to my new iphone4 from my old iphone3

    Hello, just received my new iphone 4, need help in transfering data from my old iphone 3 photos, emails etc. apps, thank you

    http://support.apple.com/kb/ht2109

  • Need help in oracle data recovery

    Friends ,i need help in oracle data recovery.
    I had an oracle 8i database running on windows.
    For some reason Windows operating system crashed.
    It is not booting up.
    I dont have current backups.But my database physical files are in the disk.
    Controlfile,datafiles and redo log files are there.
    Is there any way I can recover my database?
    Please help in this issue.
    regards
    Ajith

    HI citrus,
    thanks for the reply.
    I have installed database 9i on the same PC after O/S reinstallation.
    You are saying that ,I need to keep oracle root folder same as that of my old installation ,and copy control files,redo log and data files in exactly same folders as that of old database,and then start the database?
    thank you for your patience and support.
    regards.,
    Ajith

  • I need help proving the date tag on a photo stored in my iPhoto is from the date it was sent to my iphone/date it was imported into iphoto - and that it is NOT the date the photo was actually taken.  Please help!

    I need help proving the date tag on a photo stored in my iPhoto is from the date it was sent to my iphone/date it was imported into iphoto - and that it is NOT the date the photo was actually taken.   I recieved a photo via text on my iphone and then I synced my iphone to my macbook and now it is in iphoto.  I already know that the date on the photo per the tag that shows up on it in iphoto is NOT the date the photo was actually taken.  I need article or literature or something confirming the tag is from when it was sent to the iphone and/or when it was imported.  I greatly appreciate some assistance!

    All I am trying to do is find something on a forum board or article etc stating that the the date showing in iphoto could be the date it was imported or synced or sent to me and not the actual date taken.
    The date on the photo could be anything because you can edit the date with iPhoto or any of 100 apps, free and paid for. So, the date on the photo will prove nothing, I'm afraid.
    Regards
    TD

  • Need help in converting date format

    Hi,
    Need help in converting date format from 'DD-MON-YYYY' to 'YYYY-MM-DD' in an .rtf template as I believe xml publisher supports the date format as 'YYYY-MM-DD' only.
    Thanks,
    Raj.

    I got the same problem, anyone know how to solve this problem? I allready found some date functions on http://blogs.oracle.com/xmlpublisher/2008/09/date_functions.html . I also tried <?xdoxslt:month_name(xdoxslt:get_month(xdofx:substr(NEED_BY_DATE, 4,3)), $_XDOLOCALE), 0, 'nl-NL')?>, but then it returns a namespace error (Caused by: oracle.xdo.parser.v2.XPathException: Namespace prefix 'xdofx' used but not declared.). Anyone know how to fix this?
    Edited by: user11165753 on 7-dec-2009 23:50

Maybe you are looking for

  • Want to fire event receiver before workflow is execute while adding File in Document Library.

    Hi, I have Event receiver and workflow attached to same Document Library. Is it possible to fire event receiver before Workflow is executed ? Regards, Milind

  • 10133 ADF: How to stop search button to execute when there is an error

    Hi, I have two dropdownlists in a search criteria on a search page. The search result is at the bottom of the same page. The two values in the dropdownlists need to be validated when the search button is clicked. The validation logic is put in the se

  • Urgent!! HTTP to File scenario

    Hey guys i have a client who is sending Invoices to our company through HTTP over internet in XML format.he send this Invoice to our IP address and port and the firewall has been configured to allow Invoices coming to this IP and port. do we need to

  • Extraction program for EH&S (EH&S to XI scenario)

    Dear Experts, I am from the XI background and am new to EH&S. I would like to know whether there exists an extraction program to extract substance data from EH&S(ECC) and send it to XI. If yes then what is it? The EH&S team here doesn't know of any k

  • Equations Hidden in Indesign

    Hello, does anyone have a solution for hidden  Equations in Indesign, The Equations links not missing in indesign file, but i got big problem in that these equations not viewed in particular page.