Solved

PL/SQL UTL_FILE FOPEN

Posted on 2004-10-27
6,450 Views
Last Modified: 2012-06-21
If I use the FOPEN command to open a file, then how do I check if the file was not opened?

What I need to do in PL/SQL is to check if a file exists, if it does then I want to perform some database operations, that do not deal with the file.  Then delete the file.  I don't need to read or write to the file.

Thanks
0
Question by:Intern
    6 Comments
     
    LVL 75

    Expert Comment

    by:slightwv (䄆 Netminder)
    How to check if it  opened:  No exception thrown:  probably opened.

    When in doubt: UTL_FILE.IS_OPEN

    Just to see if it exists:  ??? don't think there is a specific function for this.  I'd probably just do a quick readonly open then close.

    delete the file: UTL_FILE.FREMOVE
    0
     
    LVL 75

    Accepted Solution

    by:
    I was incorrect in the previos statement:

    You can check if the file exists by using: FGETATTR

    Check out:
    http://download-west.oracle.com/docs/cd/B10501_01/appdev.920/a96612/u_file2.htm#1002542
    0
     
    LVL 1

    Author Comment

    by:Intern
    Thanks, could you give me a sample syntax of this command and checking if the file is open?

    i.e.
    DECLARE
    vInHandle utl_file.file_type;
    BEGIN
      vInHandle := utl_file.fopen('DIR', 'test.txt', 'R');
      IF utl_file.is_open(vInHandle) THEN
        utl_file.fclose(vInHandle);
        utl_file.fremove('DIR', 'test.txt);
      ELSE
       // Do something else
      END IF
    END fopen;

    Is this right??
    0
     
    LVL 1

    Author Comment

    by:Intern
    Guess I am to slow, I will check it out.
    0
     
    LVL 75

    Expert Comment

    by:slightwv (䄆 Netminder)
    Are you still in need of assistance?
    0
     
    LVL 1

    Author Comment

    by:Intern
    Thanks alot, worked like a charm.
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
    Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
    This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
    This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

    875 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now