Appending data to file by using utl_file
DBAsupport.com Forums - Powered by vBulletin
Results 1 to 3 of 3

Thread: Appending data to file by using utl_file

  1. #1
    Join Date
    Aug 2002
    Posts
    3

    Appending data to file by using utl_file

    I am using oracle 8.1.7 .
    I have written a stored procedure which writes data in to a file by using utl_file.
    now i want to append some data at the end of the first line in the same file. How can we do it?. Can we move the file pointer to whatever the position just we do it in C (like by fseek()) ?
    thank u

  2. #2
    Join Date
    Mar 2001
    Location
    Reading, U.K
    Posts
    598
    this is just an example

    declare
    fname VARCHAR2(40);
    floc VARCHAR2(20) := '/opt/oracle/utldir'; -- file location
    ftype UTL_FILE.FILE_TYPE;
    cursor cur_accstmt is select a, b from testme;
    begin
    dbms_output.put_line('Start time : '||to_char(sysdate,'HH24:MI:SS'));
    fname := 'acctstmt'||sysdate||'.dat';
    dbms_output.put_line(fname);
    ftype := utl_file.fopen(floc,fname,'w');
    For i in cur_accstmt loop
    utl_file.put_line(ftype,
    i.A||'|'||
    i.B
    );
    utl_file.new_line(ftype,0);
    end loop;
    if utl_file.is_open(ftype) then
    utl_file.fclose(ftype);
    end if;
    dbms_output.put_line('End time : '||to_char(sysdate,'HH24:MI:SS'));
    end;
    /
    Cheers!
    OraKid.

  3. #3
    Join Date
    Dec 2000
    Location
    Ljubljana, Slovenia
    Posts
    4,439

    Re: Appending data to file by using utl_file

    Originally posted by rk0000
    I am using oracle 8.1.7 .
    I have written a stored procedure which writes data in to a file by using utl_file.
    now i want to append some data at the end of the first line in the same file. How can we do it?.
    AFAIK you can't do that by UTL_FILE, at least not in 8.1.7. It is possible in 9i, by reading the original file, storing changed contents in new file and finaly by renaming new file to original file with overwrite option (UTL_FILE.FRENAME(overwrite=>TRUE, ....)).
    Jurij Modic
    ASCII a stupid question, get a stupid ANSI
    24 hours in a day .... 24 beer in a case .... coincidence?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width