Results 1 to 8 of 8
  1. #1
    Join Date
    Jul 2002
    Posts
    227

    Unanswered: write on a file with utl_file

    I know that I can write on a file with UTL_FILE package.
    I tried it and it run correctly:

    DECLARE
    FileHandler UTL_FILE.FILE_TYPE;
    BEGIN
    fileHandler := UTL_FILE.FOPEN('c:\', 'utl.txt', 'w');
    UTL_FILE.PUTF(fileHandler, 'test on file');
    UTL_FILE.FCLOSE(fileHandler);
    EXCEPTION
    WHEN utl_file.invalid_path THEN
    raise_application_error(-20000, 'ERROR: Invalid path for file or path not in INIT.ORA.');
    END;

    Now if I have a table with 100 records I don't know how can I read from this table and then write the records on file.

    Is it possible with UTL_FILE package?

    Thanks
    Raf

  2. #2
    Join Date
    Jul 2003
    Posts
    12

    Re: write on a file with utl_file

    Hi,
    I had the same thing and I used UTL_FILE packge also, in your case, you shoud use a cursor to get all rows in the table you need to write on file. After that you use For loop to write on file by the syntax: UTL_FILE.PUT_LINE(.....);
    Regards,

    Originally posted by raf
    I know that I can write on a file with UTL_FILE package.
    I tried it and it run correctly:

    DECLARE
    FileHandler UTL_FILE.FILE_TYPE;
    BEGIN
    fileHandler := UTL_FILE.FOPEN('c:\', 'utl.txt', 'w');
    UTL_FILE.PUTF(fileHandler, 'test on file');
    UTL_FILE.FCLOSE(fileHandler);
    EXCEPTION
    WHEN utl_file.invalid_path THEN
    raise_application_error(-20000, 'ERROR: Invalid path for file or path not in INIT.ORA.');
    END;

    Now if I have a table with 100 records I don't know how can I read from this table and then write the records on file.

    Is it possible with UTL_FILE package?

    Thanks
    Raf

  3. #3
    Join Date
    Dec 2003
    Location
    India
    Posts
    12
    For writing in a utl file the location of the utl file should be set in intit.ora file .Check the parameter utl_file_dir in init.ora file or in v$parameter

  4. #4
    Join Date
    Mar 2004
    Posts
    205
    Even that I tried by giving

    utl_file_dir=/ora8/test

    Still It was not appended with the text

  5. #5
    Join Date
    Mar 2004
    Posts
    205
    The above path was in my unix machine "/ora8/test is the dir"

  6. #6
    Join Date
    Jun 2004
    Location
    Liverpool, NY USA
    Posts
    2,509
    Quote Originally Posted by SamCute
    Even that I tried by giving

    utl_file_dir=/ora8/test

    Still It was not appended with the text
    When you do the fopen, instead of
    fileHandler := UTL_FILE.FOPEN('c:\', 'utl.txt', 'w');
    you would do.
    fileHandler := UTL_FILE.FOPEN('c:\', 'utl.txt', 'a');
    Bill
    You do not need a parachute to skydive. You only need a parachute to skydive twice.

  7. #7
    Join Date
    Mar 2004
    Posts
    205
    Even this I tried by having my utl.txt file in my system
    But it was not appending

  8. #8
    Join Date
    Jun 2004
    Location
    Liverpool, NY USA
    Posts
    2,509
    Utlfile can only write to directories on the database server. Is the directory "c:\" actually on the database server (windows server) and is c:\ defined in the init.ora for the database?
    Bill
    You do not need a parachute to skydive. You only need a parachute to skydive twice.

Posting Permissions

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