Use of UTL_FILE package

Hi,
I am trying to use the following command:
UTL_FILE.FOPEN('/HOME/SCMS/DUNNING/OUTPUT/','DUNNING_ACCT_YYYYMMDD.PSC','W');
however i get an error invalid directory name.
can anyone please advise how to assign the location as the name of a local directory eg....D:\xyz

You need to use CREATE DIRECTORY statement to create a directory and use that name in fopen.
SQL> CREATE DIRECTORY mydir AS '/appl/gl/log';
SQL> GRANT READ ON DIRECTORY mydir TO DBA;
DECLARE
  V1 VARCHAR2(32767);
  F1 UTL_FILE.FILE_TYPE;
BEGIN
  -- In this example MAX_LINESIZE is less than GET_LINE's length request
  -- so the number of bytes returned will be 256 or less if a line terminator is seen.
  F1 := UTL_FILE.FOPEN('MYDIR','MYFILE','R',256);
  UTL_FILE.GET_LINE(F1,V1,32767);
  UTL_FILE.FCLOSE(F1);
  -- In this example, FOPEN's MAX_LINESIZE is NULL and defaults to 1024,
  -- so the number of bytes returned will be 1024 or less if a line terminator is seen.
  F1 := UTL_FILE.FOPEN('MYDIR','MYFILE','R');
  UTL_FILE.GET_LINE(F1,V1,32767);
  UTL_FILE.FCLOSE(F1);
  -- In this example, GET_LINE doesn't specify a number of bytes, so it defaults to
  -- the same value as FOPEN's MAX_LINESIZE which is NULL in this case and defaults to 1024.
  -- So the number of bytes returned will be 1024 or less if a line terminator is seen.
  F1 := UTL_FILE.FOPEN('MYDIR','MYFILE','R');
  UTL_FILE.GET_LINE(F1,V1);
  UTL_FILE.FCLOSE(F1);
END; This is an example from Oracle docs. You better go through that first.
Cheers
Sarma.

Similar Messages

  • Samples using UTL_FILE package

    hello;
    I would like to use the utl_file package: fopen, put_line ...
    can you send me some samples using this package.
    thanks to your help
    mam
    null

    declare
    T1 UTL_FILE.FILE_TYPE;
    begin
    begin
    T1:= UTL_FILE.FOPEN
    ('/u02/applmgr/10.7p161/eye/3.3.1/out','filename.dat','w');
    EXCEPTION
    WHEN UTL_FILE.INVALID_PATH THEN
    DBMS_OUTPUT.PUT_LINE('Invalid Path');
    WHEN UTL_FILE.INVALID_MODE THEN
    DBMS_OUTPUT.PUT_LINE('Invalid Mode');
    WHEN UTL_FILE.INVALID_OPERATION THEN
    DBMS_OUTPUT.PUT_LINE('Invalid Operation');
    end;
    UTL_FILE.PUT(T1,'PROD DATE ');
    UTL_FILE.PUT(T1,'PRODUCT ');
    UTL_FILE.PUT_LINE(T1,'INTEREST TYPE ');
    UTL_FILE.PUT(T1,'LEASE NUMBER ');
    begin
    UTL_FILE.FCLOSE(T1);
    EXCEPTION
    WHEN UTL_FILE.WRITE_ERROR THEN
    DBMS_OUTPUT.PUT_LINE('write error');
    WHEN UTL_FILE.INVALID_FILEHANDLE THEN
    DBMS_OUTPUT.PUT_LINE('Invald File Handle');
    end;
    END;
    mamoudou (guest) wrote:
    : hello;
    : I would like to use the utl_file package: fopen, put_line ...
    : can you send me some samples using this package.
    : thanks to your help
    : mam
    null

  • Writing files using UTL_FILE package

    Greetings:
    I'm attempting to write simple text files on the server side using the UTL_FILE package.I can get it to write the file to a local drive on the Oracle server with no problems, but not a network drive. When trying to write to a network drive, the FOPEN function raises the UTL_FILE.INVALID_OPERATION exception. This is even with my UTL_FILE_DIR parameter set the * for all directories and I have "Full Control" permission on the directory. I am running in a NT Server/Wkstn environment. Anyone have any ideas why I can't write a file to a network drive?
    Thanks a lot,
    Chris Scopp

    Thanks for your response...
    I have set the UTL_FILE_DIR parameter... I've tried setting it to the * for all directories and also mapping a drive letter from the server to where I want to write the file and then explicitly naming this path in the UTL_FILE_DIR parameter. Neither works, I still get the INVALID_OPERATION exception raised on the FOPEN function. I'm convinced now that it does have something to do with NT because I have been able to do the same operation writing to a Win95/98 box and it works fine. I have "Full Control" to all places I'm trying to write to, any other ideas?
    Thanks a lot,
    Chris Scopp

  • Error while using UTL_FILE package

    I am getting error while using UTL_FILE package in apex 3.0 version
    Pls help me out.

    ok, how are you using UTL_FILE and what is the error?

  • Need to generate the excel file with diffrent sheets using utl_file package

    Hi,
    Sorry for previous message in which I had missed the usage of " UTL_FILE " package
    I need to generate the excel file with diffrent sheets . Currently I am generating the data in three diffrent excel files using
    " UTL_File " package and my requirement is to generate this in a single excel file with diffrent sheets.
    Please help on this
    Thanks & Regards,
    Krishna Vyavahare

    Hello 10866107,
    at Re: How to save a query result and export it to, say excell? you can find links to different solutions. At least the packages behind second and fourth link support more than one worksheet.
    Regards
    Marcus

  • Permissions on files created using UTL_FILE package

    The files created on unix using UTL_FILE package have permisisons rw- - - - - - -.(600). I want them to be created with permissions 640.(rw-r - - - - - ).i.e read access to the group also. The umask setting of the unix account of the oracle instance are 137. Is there any way to create the files with the required permissions.

    So SQL*Plus is on your PC? I'm assuming you mean 'call' as in the windows cmd.exe command?
    Sheesh this is like getting blood from a stone.
    In that case you must be connecting via the listener and not internally.
    In which case the umask comes from the umask that was set in the environment of the OS user who started the listener process.
    Thats not necessarily the same as the owner of the oracle software (normally 'oracle').
    If sysdamin joebloggs logs in and starts the listener manually in a shell, then the umask applied to all shadow processes started by the listener is whatever jobloggs umask was when he typed the command 'lsnrctl start'. The umask of the owner of the oracle software, or your umask, is utterly irrelevent.
    So if you don't like the umask for files created by processes spawned by the listener, stop and restart the listener in a shell where you have explicitly set the umask to what you want it to be.
    Really starting the listener should be scripted and the correct umask is put in the script just before the call to 'lsnrctl start'.

  • Creating Error log files using UTL_FILE package on a remote machine

    Database Version: 10g Release2
    OS Platform: Sun Solaris
    I have been asked to log errors to OS files rather than tables. So, i wanted to use UTL_FILE package. But the client doesn't want to store these files on the same server where the database is running(as specified in UTL_FILE_DIR). Is there a way i could get these files created on a remote machine(client).

    I believe what others are suggesting is that your stored procedure continues to log to a table and a separate process be created that runs on the machine you want the file to be created on which reads the log table and writes to a log file.
    If that is not an option, can you expose the directory on the remote machine you want to write the file to as a file share that can be mounted by the database server? If you can, you could write errors there using UTL_FILE. However, it would probably be a bad idea. If you're logging an error already, that implies that something has gone wrong. Making an error logging process dependent on a remote server being available and properly mounted with appropriate privileges at the instant the error occurs just creates more sources of failure that would prevent you from logging an error, which would prevent you from being able to debug the problem or even know it existed without a report from a user.
    Justin

  • Archiving files generated by PL/SQL program using UTL_FILE package

    Dear All,
    We have on PL/SQL package that is generating some data files using UTL_FILE package in one specific directory.
    I am working on concurrent program of type host(unix script) to move generated file to some archive folder.
    Now the problem is owner of the files generated by PL/SQL is oracle and file permissions of the generated files are 644(Only read permission for group and others).
    Concurrent program is using an another os user applmgr to execute the script attached with concurrent program.
    Because applmgr is not having write permission on the files, hence mv command is failing.
    Please suggest me how to resolve this issue.
    Regards
    Devender Yadav

    Hi;
    I just think that, you can create one sh which is chancing permission of related path owner for applmgr user and put it on crontab and it can run every 1 min.
    Regard
    Helios

  • Reading all files on directory using "utl_file" package...

    I need to read all files in directory via PL/SQL. I don't know
    name files (are data dynamics create for automation system),
    only I know your extensions.
    Can I do this using the package "utl_file" or I need to create
    program in another language (C, C++, for example)?
    Any ideas...
    Thanks.

    Hi,
    you can't do that with the UTL_FILE package (it can't retrieve
    file names).
    A very simple solution would be, if you created on OS-level a
    file which contains the filenames of directory and then read this
    file using UTL_FILE. With the information on all file names you
    can enter a loop which opens and reads all files again using
    UTL_FILE.
    A more mundane solution could be to use the features on the iFS.
    Cheers
    Gerald

  • Unable to write files in different m/c in LAN using utl_file package

    I need to dump some files generated by utl_file package in a separate m/c not in the db server.For that I tried using utl_file_dir='*' and mapped the specified directory in the db server. but its failing as show below..
    ORA-29283: invalid file operation
    ORA-06512: at "SYS.UTL_FILE", line 449
    ORA-29283: invalid file operation
    ORA-06512: at "ANIRBAN.WRITE_IN_FILE", line 9
    ORA-06512: at line 1
    The prototype sp is given below..
    CREATE OR REPLACE PROCEDURE write_in_file(pInDir IN VARCHAR2,
    pInFileName IN VARCHAR2,
    pInFileContent IN VARCHAR2) IS
    vFile UTL_FILE.FILE_TYPE;
    vFileName VARCHAR2(20) := pInFileName;
    BEGIN
    dbms_output.enable(1000000);
    vFile := UTL_FILE.FOPEN(pInDir, vFileName, 'w', 32000);
    UTL_FILE.PUT_LINE(vFile, pInFileContent);
    UTL_FILE.FCLOSE(vFile);
    END write_in_file;
    With this sp i'm able to write in genuine drives but not in mapped one.What shall be done to be able to write in a separate m/c freely.Plz guide me

    And make sure you specify the full path name of the server/directory path rather than using substituted drive names as is can sometimes be funny about that sort of thing.

  • Create a file and store it in the database using UTL_FILE package

    Hello.
    I'm using UTL_FILE package to store data from a table into an excel file but I don't know how to store this file in a table with a BLOB field the database at the same time. I want do do this because I will use it in a Oracle Portal.
    Anybody has any idea how to do this?
    Thanks & Regards,
    Alexandra

    From Asktom
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:232814159006

  • Error Using Directories and UTL_FILE package

    Dear All, I have a problem using UTL_FILE package...
    When I'm trying to write into a directory I get the following error message:
    ORA-29283: invalid file open
    I have a Directory named "TMPDIRPD". I checked the permissions over this directory and found that
    'OPS$PDRVBPP' user has OS permissions over it. I supposed that it was the user used to validate permissions.
    Plus, I verified that user "OPS$PDRDVBPP" has read/write permission into directory with this query:
    SELECT TP.grantee,
    TP.privilege
    FROM dba_tab_privs TP,
    dba_role_privs RP
    WHERE TP.table_name = 'TMPDIRPD'
    AND TP.grantee = RP.granted_role
    AND rp.grantee = 'OPS$PDRDVBPP';
    But I'm getting the same error message.
    Then I saw that 'OPS$PDRDVBPP' user calls UTL_FILE package through another package, and isn't the owner of it...
    This package - who belongs to another database user - is using the OS user who owns the Oracle Installation instead 'OPS$PDRVBPP'. Isn't it?
    I also checked that operative system user has read-write permissions, and asked it to the OS Administrator. He told me that oracle user has read-write permissions over this directory too... I don't know what more else can be wrong.
    Have anyone some idea to fix this?

    Roman, I sorry about missed info.
    This is the version:
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Prod
    PL/SQL Release 10.2.0.4.0 - Production
    "CORE     10.2.0.4.0     Production"
    TNS for Linux: Version 10.2.0.4.0 - Production
    NLSRTL Version 10.2.0.4.0 - Production
    It's running over a Unix server (I really don´t know the exact version but it's a suse Linux).
    I though in ORACLE Directory object named TMPDIRPD, and its directory_path defined like /companyFiles/thishost/proj/pdrdvbpp/appfiles/tmp (OS Directory).
    I wrote into a OS directory using one of the procedures or functions inside the UTL_FILE package (SYS.UTL_FILE.FOPEN(parameter_path,parameter_file,parameter_io)).
    Here it goes an example of code.
    DECLARE
    v_AbroLog UTL_FILE.FILE_TYPE;
    BEGIN
    v_AbroLog := UTL_FILE.FOPEN('TMPDIRPD','log_prueba_utl.'||to_char(sysdate,'mmddy
    yyy'), 'a');
    UTL_FILE.PUT_LINE(v_AbroLog,'PRUEBA OK');
    UTL_FILE.FCLOSE(v_AbroLog);
    END;
    quit
    SQL> @test_utl.sql;
    DECLARE
    ERROR at line 1:
    ORA-29283: invalid file open
    some other generic error messages
    This error happens when the file doesn't exists.

  • Problem in using UTL_FILE Package

    Dear Mates,
    I am trying to make use of UTL_FILE for inseting data in to the tables by reading the contents of a text file. I have set the UTL_FILE_DIR parameter by giving the path. Still i am not able to insert the records to the table.
    The error I am getting is
    ERROR at line 1:
    ORA-06510: PL/SQL: unhandled user-defined exception
    ORA-06512: at "PRASANNA.LOADSTUDENTS", line 61
    ORA-06512: at line 1
    I have set the parameter UTL_FILE_DIR in INIT<SID>.ORA as
    UTL_FILE_DIR=C:\developer
    please help me out
    It will be helpful if you can mail me at [email protected]

    ORA-06512: at "PRASANNA.LOADSTUDENTS", line 61how looks like line 61 in your PRASANNA.LOADSTUDENTS function?
    what's happening there?
    From "Oracle Product Document Library":
    ORA-06512 at string line string
    Cause: Backtrace message as the stack is unwound by unhandled exceptions.
    Action: Fix the problem causing the exception or write an exception handler for this condition. Or you may need to contact your application administrator or database administrator.

  • Problem Loading Data Using UTL File Package

    Hi Friends..
    My Database is Oracle 10gR2 and OS is WINDOWS.
    I have one excel file which contains 10 fields.
    My requirement is to Load data from 1 excel file into two tables..
    tables are master and detail
    Below are sample data and structure for it..
    Excel file format
    TEST.CSV
    Srno Empno Empname City Challanno challandate Materialno materialname Materialqty Materialcost
    1     232 raj      Hyderabad      533     20/04/2010     11     abc      34     10
    1     232 raj      Hyderabad      533     20/04/2010     12      aa      4     110
    1     231 ram Baroda      533     20/04/2010     14      abcd      33     210
    Master table
    empno
    Challanno
    challandate
    Detail table
    empno
    materialno
    materialname
    materialqty
    materialcost
    My question is ..While reading 1st line if its empno is new then record is entered in master table for the first time and remaining records of same empno is entered in detail table.. now when empno no changes then new entry is done in master table and associated records are entered in detail table..
    So in this case for empno 232 master table would have
    232,533,20/4/2010
    Detail table for empno 232 would now have 2 records..
    232,11,abc,34,10
    232,12,aa,4,110
    I am using UTL_FILE package to achieve this as the file is on server...
    Kindly please help me to proceed in this..
    Really appreciate your help...

    sai121 wrote:
    Its ok..if u dont wanna reply sir... but thats what i m told to do..and i have 4yrs of industry experience too...but cant argue with boss..u know that right.It's not that people don't want to reply, it's that what you're asking for is something achieved very simply in a few lines of code using External tables but is a convoluted and complex thing to do using UTL_FILE, so why would anybody want to waste their time giving you a load of code to achieve what you want when they know it's the wrong approach anyway.
    I've been computer programming for 28 years (jeez has it really been that long :D ), so I wouldn't be telling you that you're doing it the wrong way without knowing that there are better ways to do it and you're asking for the wrong way. Speak with your boss, tell him that you've been recommended to use External Tables instead because they're the right way to read such data and UTL_FILE is not the right approach.

  • How to manage two OS Text files in UTL_FILE Package simultaneously?

    Hi
    I am using UTL_FILE Package in order to insert rows into my table from the OS text files.
    It inserts the row in one of the column in the table successfully.
    But when I change the code in following routine in order to insert two rows from the two OS text files, it fails and no row inserted in any column of the table.
    Could someone assist what changes I will do in the following script in order to insert the rows in both the columns of the table from the two different OS Text files simultaneously?
    The UTL_FILE_DIR parameter is set to * .
    I am using Oracle 8.1.7.
    Following is the procedure, which I am trying to insert the rows in two columns at a time:
    Regards
    Sharbat
    Declare                              
    l_file_handle1 UTL_FILE.FILE_TYPE;
    l_file_handle2 UTL_FILE.FILE_TYPE;                              
    l_buffer1 VARCHAR2(4000);
    l_buffer2 VARCHAR2(4000);                              
    BEGIN                              
    l_file_handle1 := UTL_FILE.FOPEN('c:\Test\Result', 'System_Name.txt', 'r', 4000);                              
    l_file_handle2 := UTL_FILE.FOPEN('c:\Test\Result',
    'Machine.txt', 'r', 4000);
    loop
    UTL_FILE.get_line(l_file_handle1,l_buffer1);
    UTL_FILE.get_line(l_file_handle2,l_buffer2);
    insert into test (Hostname,Machine) values(l_buffer1,l_buffer2);
    commit;
    end loop;
    exception
    when no_data_found then
    UTL_FILE.FCLOSE(l_file_handle1);
    UTL_FILE.FCLOSE(l_file_handle2);
    when others then
    if utl_file.is_open(l_file_handle1)
    then
    utl_file.fclose(l_file_handle1);
    end if;
    if utl_file.is_open(l_file_handle2)
    then
    utl_file.fclose(l_file_handle2);
    end if;
    end;

    I recommend you to post this here to get fast answer:
    PL/SQL
    Joel Pérez

Maybe you are looking for

  • Is it possible to delete the origional appleID email adress?

    Hello, I have a little problem: My father has a email adress corresponding to his internet connection, with this email adress he created an appleID (serveral years ago). So he has an apple id using "[email protected]" including an icloud email adress

  • WSConfig problem when connecting to Portal with Netweaver Business client

    Hello everybody, I am trying to connect to an existing portal (7.0) with the new Netwevaer Business client. On one system, it works - on the other, it doesn't. The client tries to call the url: http://<host>:<j2ee-port>/NavigationWS/NavigationWSConfi

  • Batch Scheduler Failing Randomly

    Hi all - I have a batch scheduled to run on demand.  It runs on ~130 custom members.  A few months ago it started failing on random custom members.  It will run successfully on most, but failed on some with the error: Problems encountered in "Financi

  • Stuck on grey screen with apple logo what do i do

    Firefox would not close so I restarted computer and now its stuck on the grey screen with the apple logo. What do I do?

  • Display Total page number in exicutable prg while run in Back ground

    Hi All, The Logic for Total Pages in Exicutable prg is :- v_temp = v_totpage. do v_totpage times. read line 1 of page sy-index. replace '@@@' in sy-lisel with v_temp. modify line 1 of page sy-index. enddo. TOP-OF-PAGE. format color col_heading. write