(8.0.5+) UTL_FILE PACKAGE사용시 READ_ERROR/WRITE_ERROR

제품 : PL/SQL
작성날짜 : 2002-11-22
(8.0.5+) UTL_FILE PACKAGE사용시 READ_ERROR/WRITE_ERROR
===================================================
Problem Description
PLSQL에서 UTL_FILE package을 사용하여 text file를 read 하고 write할때
1023 byte 이상의 파일을 읽고 쓰고자 할때 다음의 ERROR을 만나게 된다.
UTL_FILE.WRITE_ERROR
UTL_FILE.READ_ERROR
User-defined exception
8.0.5 이전에는 UTL_FILE package을 사용하여 file을 다룰때 1023 byte이상의
데이터를 읽지 못하는 제한이 있었다. 하지만 8.0.5 이후에는 32,767 까지
사용 가능하다. 디폴트 최대 라인 싸이즈는 1023이지만 이것을 UTL_FILE.FOPEN
function에 MAX_LINESIZE 파라메터를 이용하여 해결 가능하다.
Default:
FUNCTION fopen(location IN VARCHAR2,
filename IN VARCHAR2,
open_mode IN VARCHAR2)
RETURN file_type;
최대 라인 싸이즈를 지정하고자 할때:
FUNCTION fopen(location IN VARCHAR2,
filename IN VARCHAR2,
open_mode IN VARCHAR2,
max_linesize IN BINARY_INTEGER)
RETURN file_type;
Solution Description:
MAX_LINESIZE 파라메터를 추가한 예이다.
CREATE OR REPLACE PROCEDURE file_test IS
file_handle UTL_FILE.FILE_TYPE; -- file handle of OS flat file
retrieved_buffer VARCHAR2(32767); -- Line retrieved from flat file
BEGIN
-- Open the same file to read from
file_handle :=
UTL_FILE.FOPEN('/home/ora920/product/9.2.0/utldir','myfile.txt','R',32767);
-- UTL_FILE.FOPEN('/home/ora920/product/9.2.0/utldir','myfile.txt','R'); -- READ_ERROR
-- Read a line from the file.
UTL_FILE.GET_LINE (file_handle, retrieved_buffer);
-- Print fetched line out to the SQL*PLUS prompt.
DBMS_OUTPUT.PUT_LINE('File size is : '||LENGTH(retrieved_buffer));
-- CLose the file.
UTL_FILE.FCLOSE(file_handle);
file_handle :=
UTL_FILE.FOPEN('/home/ora920/product/9.2.0/utldir','out.txt','W',32767);
-- UTL_FILE.FOPEN('/home/ora920/product/9.2.0/utldir','out.txt','W'); --WRITE_ERROR
UTL_FILE.PUT_LINE (file_handle, retrieved_buffer);
UTL_FILE.FCLOSE(file_handle);
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('no_data_found');
UTL_FILE.FCLOSE(file_handle);
WHEN UTL_FILE.INVALID_PATH THEN
DBMS_OUTPUT.PUT_LINE('UTL_FILE.INVALID_PATH');
UTL_FILE.FCLOSE(file_handle);
WHEN UTL_FILE.READ_ERROR THEN
DBMS_OUTPUT.PUT_LINE(' UTL_FILE.READ_ERROR');
UTL_FILE.FCLOSE(file_handle);
WHEN UTL_FILE.WRITE_ERROR THEN
DBMS_OUTPUT.PUT_LINE('UTL_FILE.WRITE_ERROR');
UTL_FILE.FCLOSE(file_handle);
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('other stuff');
UTL_FILE.FCLOSE(file_handle);
END;
아래와 같이 1023 byte 이상의 record임에도 잘 읽히는 것을 볼수 있다.
SQL> set serveroutput on
SQL> exec file_test
File size is : 1921
PL/SQL procedure successfully completed.
Reference Ducumment
<Note:1026951.6>
KOREAN Bulletin : 11532

제품 : PL/SQL
작성날짜 : 2002-11-22
(8.0.5+) UTL_FILE PACKAGE사용시 READ_ERROR/WRITE_ERROR
===================================================
Problem Description
PLSQL에서 UTL_FILE package을 사용하여 text file를 read 하고 write할때
1023 byte 이상의 파일을 읽고 쓰고자 할때 다음의 ERROR을 만나게 된다.
UTL_FILE.WRITE_ERROR
UTL_FILE.READ_ERROR
User-defined exception
8.0.5 이전에는 UTL_FILE package을 사용하여 file을 다룰때 1023 byte이상의
데이터를 읽지 못하는 제한이 있었다. 하지만 8.0.5 이후에는 32,767 까지
사용 가능하다. 디폴트 최대 라인 싸이즈는 1023이지만 이것을 UTL_FILE.FOPEN
function에 MAX_LINESIZE 파라메터를 이용하여 해결 가능하다.
Default:
FUNCTION fopen(location IN VARCHAR2,
filename IN VARCHAR2,
open_mode IN VARCHAR2)
RETURN file_type;
최대 라인 싸이즈를 지정하고자 할때:
FUNCTION fopen(location IN VARCHAR2,
filename IN VARCHAR2,
open_mode IN VARCHAR2,
max_linesize IN BINARY_INTEGER)
RETURN file_type;
Solution Description:
MAX_LINESIZE 파라메터를 추가한 예이다.
CREATE OR REPLACE PROCEDURE file_test IS
file_handle UTL_FILE.FILE_TYPE; -- file handle of OS flat file
retrieved_buffer VARCHAR2(32767); -- Line retrieved from flat file
BEGIN
-- Open the same file to read from
file_handle :=
UTL_FILE.FOPEN('/home/ora920/product/9.2.0/utldir','myfile.txt','R',32767);
-- UTL_FILE.FOPEN('/home/ora920/product/9.2.0/utldir','myfile.txt','R'); -- READ_ERROR
-- Read a line from the file.
UTL_FILE.GET_LINE (file_handle, retrieved_buffer);
-- Print fetched line out to the SQL*PLUS prompt.
DBMS_OUTPUT.PUT_LINE('File size is : '||LENGTH(retrieved_buffer));
-- CLose the file.
UTL_FILE.FCLOSE(file_handle);
file_handle :=
UTL_FILE.FOPEN('/home/ora920/product/9.2.0/utldir','out.txt','W',32767);
-- UTL_FILE.FOPEN('/home/ora920/product/9.2.0/utldir','out.txt','W'); --WRITE_ERROR
UTL_FILE.PUT_LINE (file_handle, retrieved_buffer);
UTL_FILE.FCLOSE(file_handle);
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('no_data_found');
UTL_FILE.FCLOSE(file_handle);
WHEN UTL_FILE.INVALID_PATH THEN
DBMS_OUTPUT.PUT_LINE('UTL_FILE.INVALID_PATH');
UTL_FILE.FCLOSE(file_handle);
WHEN UTL_FILE.READ_ERROR THEN
DBMS_OUTPUT.PUT_LINE(' UTL_FILE.READ_ERROR');
UTL_FILE.FCLOSE(file_handle);
WHEN UTL_FILE.WRITE_ERROR THEN
DBMS_OUTPUT.PUT_LINE('UTL_FILE.WRITE_ERROR');
UTL_FILE.FCLOSE(file_handle);
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('other stuff');
UTL_FILE.FCLOSE(file_handle);
END;
아래와 같이 1023 byte 이상의 record임에도 잘 읽히는 것을 볼수 있다.
SQL> set serveroutput on
SQL> exec file_test
File size is : 1921
PL/SQL procedure successfully completed.
Reference Ducumment
<Note:1026951.6>
KOREAN Bulletin : 11532

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

  • 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

  • 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

  • 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.

  • 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

  • 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

  • Help with utl_file package

    hi
    I need to write a procedure using utl_file package to read the data from excel sheet and then checking the avaibility
    of that data in existing library. can anybody suggest me how to start with?

    Probably is better if you export your Excel as a CSV file and then map it to an external table.
    By the way, you could read the Excel file directly if you can use ODBC driver (which can be a bit tricky in an Unix system)
    Bye,
    Antonio

  • How to avoid special characters( #) via Utl_file Package

    Hello,
    I am using UTL_FILE package in order to read the text from a text file and insert this text into a table.
    But the text contain special character like #.
    This is the nature of this text data.
    For example the O/S text file contain the following text:
    TEXT:
    Name of the default schema being used in the current schema.
    Name of the default schema being used in the current schema.
    Name of the default schema being used in the current schema.
    Name of the default schema being used in the current schema.
    Name of the default schema being used in the current schema.
    Name of the default schema being used in the current schema.
    How should we avoid reading the following line via UTL_FILE from the text file?
    So the text without these special characters will be inserted into a table.
    I wanted that these special characters would not be inserted into a table via UTL_FILE.
    What code I can add in my following routine in order to avoid the reading of special characters # or a following line from the text file?
    Thanks
    Sharbat
    UTL FILE Code:
    Declare                              
    l_file_handle UTL_FILE.FILE_TYPE;                              
    l_buffer VARCHAR2(4000);                              
    BEGIN                              
    l_file_handle := UTL_FILE.FOPEN('c:\temp', 'test.txt', 'r', 4000);                              
    loop
    UTL_FILE.get_line(l_file_handle,l_buffer);
    insert into TEST (text) values(l_buffer);
    end loop;
    exception
    when no_data_found then
    UTL_FILE.FCLOSE(l_file_handle);
    when others then
    if utl_file.is_open(l_file_handle)
    then
    utl_file.fclose(l_file_handle);
    end if;
    end;

    Hi,
    in Forms you can use text_io for reading text from a file. For questions related to database packages I suggest to post this question on teh database forum here on OTN.
    Frank

  • Compile UTL_FILE PACKAGE BODY

    Hi ALL,,,
    I refreshed one db from PROD dump.
    After that I compiled all Invalid objects .But am unable to compile UTL_FILE PACKAGE BODY
    Showing all are invalid.
    OBJECT_NAME OBJECT_TYPE OWNER
    UTL_FILE PACKAGE BODY UTLFILE
    UTL_FILE_EX PACKAGE BODY UTLFILE
    UTL_FILE_ADMIN PACKAGE BODY UTLFILE
    SQL> show parameter utl
    NAME TYPE VALUE
    create_stored_outlines string
    utl_file_dir string
    Please help me how to compile this.
    If I tried to copile manualyy..I am gettimg Error like..PACAGE ALTERED WITH COMPILATION Errors.
    Thanks
    Manohar.

    Invalid objects are best compiled by using
    sqlplus / as sysdba
    @?\rdbms\admin\utlrp
    This will report the number of invalid objects when finishing.
    When you still have invalid objects you should query dba_errors where name='<name of invalid object>'
    All Oracle provided sources are in
    %ORACLE_HOME%\rdbms\admin
    You can simply find or grep for utl_file.
    There always will be two files
    utl<facility>.sql (or dbms<facility>.sql) and prvt<facility>.plb
    You need to run them both in sqlplus connected as sysdba.
    Sybrand Bakker
    Senior Oracle DBA

Maybe you are looking for

  • How do i get all my songs back after itunes gets unistalled?

    I just recently unistalled Windows (iTunes and everything else got deleted) due to my computer issues. I have reinstalled it now but my library is cleared of songs.Is there any way that I can get the songs that are on my iPod back onto iTunes? Thanks

  • Two status for one idoc while IDOC_STATUS_WRITE_TO_DATABASE, giving error

    Hi I am using a Z function module to process an incoming idoc (custom process code). While using the test tool WE19, I am trying to process an idoc. When I am using Inbound Function Module tab, the idoc is processing normally. But when I am using Sta

  • New iMac - only want iTunes & iPhoto

    My friend just got a brand new 27" iMac. She has a 2008 Mac Pro that she only wants iTunes (including her iPhone & iPad backups) and iPhoto from. Best way to do this? I'm thinking just transfer the two libraries to an external drive and then drag the

  • Comments on the Gem Cutter docs

    <div><span style="font-family: Helvetica; font-size: 12px" class="Apple-style-span">Thought I'd make some notes on this as I read through it. Overall, it's a very nice intro to the tool and what it can do.</span></div><div><span style="font-family: H

  • Dreamweaver and Safari - colors not showing up

    I am creating a web site in Dreamweaver, and when I preview it in Safari my background colors do not show up at all. They look fine in Firefox and in mobile device previews. Anyone have any ideas on how to correct this? Thanks!