Procedure using utl_file.fopen

Hi ,
I want to open a file ,read it line by line and if i find one particular word i want to display the whole line.
I tried writing a procedure but not getting desired output.
DECLARE
x utl_file.file_type;
y varchar2(200);
BEGIN
x:= utl_file.fopen('TRACE1',DB_ora_111_trc.txt','R');
LOOP
BEGIN
UTL_FILE.GET_LINE(x,y);
if x='select' then
dbms_output.put_line(x);
end if;
EXCEPTION
WHEN NO_DATA_FOUND THEN EXIT ;
END;
END LOOP;
utl_file.fclose(x);
END;
Here i am opening a tkprof file and trying to grep for select word and if it is found,display the whole select query.The above is not showing any output.Kindly assist me since i am new to coding.
Thanks

user10698496 wrote:
Hi,
I am getting only these much as my output . I want to see entire select query.DECLARE
f utl_file.file_type;
s varchar2(2000);
BEGIN
f := utl_file.fopen('TRACE1','DB_ora_1118250.trc.txt','R');
LOOP
BEGIN
UTL_FILE.GET_LINE(f,s);
if lower(s) like '%select%' then
dbms_output.put_line(s);
end if;
EXCEPTION
WHEN NO_DATA_FOUND THEN EXIT ;
END;
END LOOP;
utl_file.fclose(f);
END;
SELECT uid,tname,str,acol,hcol,TO__CHAR(u_time,'DD-MM-YYYY
SELECTgroup,name,address1,state,country,fax_no,
PL/SQL procedure successfully completed.
Ok, so that is telling us that you have your queries split over multiple lines?
In that case you need to "switch on" the output of lines from the moment you find a "select" and then switch it off again when you get a line that indicates the end of the select. So let's assume your selects end with a ";" as the last character on the last line of the select, you can do something like this...
DECLARE
  f utl_file.file_type;
  s varchar2(2000);
  in_select boolean;
BEGIN
  f := utl_file.fopen('TRACE1','DB_ora_1118250.trc.txt','R');
  in_select := false;
  LOOP
    BEGIN
      UTL_FILE.GET_LINE(f,s);
      if lower(s) like '%select%' or in_select then
        dbms_output.put_line(s);
        in_select := not(s like '%;'); -- stop when we get to ";" at end of a line.
      end if;
    EXCEPTION
      WHEN NO_DATA_FOUND THEN EXIT ;
    END;
  END LOOP;
  utl_file.fclose(f);
END;
Also i attempted to cut only table name from the output select query.I tried something like o :=substr(s,instr(s,'from')+4);PFB the code and output.Pls let me know where am i going wrong.
DECLARE
2  f utl_file.file_type;
3  s varchar2(2000);
4  op varchar2(1000);
5  BEGIN
6  f := utl_file.fopen('TRACE_EXTRACT','DB_ora_1118250.trc.txt','R');
7  LOOP
8  BEGIN
9  UTL_FILE.GET_LINE(f,s);
10  if lower(s) like '%select%' then
11  op :=substr(s,instr(s,'from')+4);
12  dbms_output.put_line(op);
13  end if;
14
15  EXCEPTION
16  WHEN NO_DATA_FOUND THEN EXIT ;
17  END;
18  END LOOP;
19  utl_file.fclose(f);
20  END;
21  /
ECT uid,tname,str,acol,hcol,TO__CHAR(u_time,'DD-MM-YYYY
ECTgroup,name,address1,state,country,fax_no,
that's because there is no "from" on those lines, so the result of the instr is 0 and you are adding 4, so you are getting all characters from character 4 onwards.
What you need in conjunction with my above suggestion is something like this...
DECLARE
  f utl_file.file_type;
  s varchar2(2000);
  in_select boolean;
BEGIN
  f := utl_file.fopen('TRACE1','DB_ora_1118250.trc.txt','R');
  in_select := false;
  LOOP
    BEGIN
      UTL_FILE.GET_LINE(f,s);
      if lower(s) like '%select%' or in_select then
        dbms_output.put_line(s);
        if lower(s) like '%from%' then
          dbms_output.put_line('TABLES: '||substr(s,instr(s,'from'+5))); -- +5 to get past the from and the space character after it.
        end if;
        in_select := not(s like '%;'); -- stop when we get to ";" at end of a line.
      end if;
    EXCEPTION
      WHEN NO_DATA_FOUND THEN EXIT ;
    END;
  END LOOP;
  utl_file.fclose(f);
END;
/

Similar Messages

  • Error while using UTL_FILE.FOPEN

    sir,
    when i write procedure using utl_file.fopen i am getting error as it must be declared PLS-00201. what mistake, i am doing.
    yours
    dr.s.r.bhattachar

    i was under the impression that there will be a moderator who will redirect the question even by mistake we post? is it not?Absolutely not. On the APEX forum we are in the fortunate position of having members of Oracle's APEX team actively involved, but neither they nor any of the other contributors perform the role of moderator or have administrative access to the forum system. The OTN team who do only really perform "moderation" when there has been a breach of the OTN Terms and Conditions.
    If your question has obviously been posted in the wrong forum, or someone thinks you will get a better response elsewhere then generally they'll suggest this, as above.

  • Broken korean characters while using utl_file.fopen

    Hi,
    I have korean data in a table and I need to extract it out.
    Am using utl_file.fopen for this. It extracts, but korean characters are coming broken...
    Is there some setting (NLS_LANG etc) that I need to do? I tried NLS_LANG korean_korea.KO16KSC5601 but didn't help...
    Thanks,
    Sachin

    Please post this question in the Database forum for an appropriate response: General Database Discussions
    Regards,
    OTN

  • PL/SQL package using utl_file.fopen gets invalid_path error

    The init.ora file has utl_file_dir = * in it. When writing a package trying to utilize the utl_file.fopen the invalid_path error always occurs. What is the fix to resolve the path error?

    create or replace package body TEST_UTL_FILE is
    -- Purpose : Sample package that uses UTL_FILE procedure(s)
    -- ===========================================================================================================
    -- Process Request
    -- ===========================================================================================================
    procedure Process_Request is
    -- Local Variable(s)
    v_file_id sys.UTL_FILE.FILE_TYPE;
    v_buffer varchar2(32767);
    begin
    v_file_id := sys.utl_file.FOPEN('D:\Oracle\XMLFiles',
    'Sample1.xml',
    'R');
    sys.utl_file.GET_LINE(v_file_id, v_buffer);
    return;
    exception
    -- Error number -29280
    WHEN UTL_FILE.INVALID_PATH THEN
    RAISE_APPLICATION_ERROR(-20001, 'invalid_path');
    -- Error number -29281
    WHEN UTL_FILE.INVALID_MODE THEN
    RAISE_APPLICATION_ERROR(-20001, 'invalid_mode');
    -- Error number -29282
    WHEN UTL_FILE.INVALID_FILEHANDLE THEN
    RAISE_APPLICATION_ERROR(-20001, 'invalid_filehandle');
    -- Error number -29283
    WHEN UTL_FILE.INVALID_OPERATION THEN
    RAISE_APPLICATION_ERROR(-20001, 'invalid_operation');
    -- Error number -29284
    WHEN UTL_FILE.READ_ERROR THEN
    RAISE_APPLICATION_ERROR(-20001, 'read_error');
    -- Error number -29285
    WHEN UTL_FILE.WRITE_ERROR THEN
    RAISE_APPLICATION_ERROR(-20001, 'write_error');
    -- Error number -29286
    WHEN UTL_FILE.INTERNAL_ERROR THEN
    RAISE_APPLICATION_ERROR(-20001, 'internal_error');
    -- Error number -29287
    WHEN UTL_FILE.invalid_maxlinesize THEN
    RAISE_APPLICATION_ERROR(-20001, 'invalid_maxlinesize');
    -- Error number -29288
    WHEN UTL_FILE.invalid_filename THEN
    RAISE_APPLICATION_ERROR(-20001, 'invalid_filename');
    -- Error number -29289
    WHEN UTL_FILE.access_denied THEN
    RAISE_APPLICATION_ERROR(-20001, 'access_denied');
    -- Error number -29290
    WHEN UTL_FILE.invalid_offset THEN
    RAISE_APPLICATION_ERROR(-20001, 'invalid_offset');
    -- Error number -29291
    WHEN UTL_FILE.delete_failed THEN
    RAISE_APPLICATION_ERROR(-20001, 'delete_failed');
    -- Error number -29292
    WHEN UTL_FILE.rename_failed THEN
    RAISE_APPLICATION_ERROR(-20001, 'rename_failed');
    -- Error number unknown
    WHEN OTHERS THEN
    RAISE_APPLICATION_ERROR(-20001, 'other_error');
    end Process_Request;
    end TEST_UTL_FILE;
    Errors:
    ORA-20001: invalid_path
    ORA-06512: at "SYS.TEST_UTL_FILE", line 21
    ORA-06512: at line 3

  • Invalid_path exception while using UTL_FILE.FOPEN

    Hi
    I am getting invalid_path exception while using the UTL_FILE.fopen subprogram. I tried finding out the reason but could not solve it. Please help.
    Below is my piece of code.
    create directory utldr as 'e:\utldir';
    declare
    f utl_file.file_type;
    s varchar2(200);
    begin
    dbms_output.put_line('1');
    f := utl_file.fopen('UTLDR','utlfil.txt','r');
    dbms_output.put_line('2');
    utl_file.get_line(f,s);
    dbms_output.put_line('3');
    utl_file.fclose(f);
    dbms_output.put_line('4');
    dbms_output.put_line(s);
    exception
    when utl_file.invalid_path then
    dbms_output.put_line('invalid_path');
    end;
    the result is:
    1
    invalid_path

    I am executing it from sys. The same user who created the directory.
    The output is as below:
    SELECT * FROM dba_directories
    OWNER     DIRECTORY_NAME     DIRECTORY_PATH
    SYS     MEDIA_DIR      d:\avale\rel4\demo\schema\product_media\
    SYS     LOG_FILE_DIR     d:\avale\rel4\assistants\dbca\logs\
    SYS     DATA_FILE_DIR     d:\avale\rel4\demo\schema\sales_history\
    SYS     EMP_DIR     E:\Oracle Directory
    SYS     REMOTED     \\10.1.1.12\oracle directory
    SYS     UTLDR     e:\utldir
    SELECT * FROM dba_tab_privs WHERE table_name='UTLDR'
    GRANTEE     OWNER     TABLE_NAME     GRANTOR     PRIVILEGE     GRANTABLE     HIERARCHY
    PUBLIC     SYS     UTLDR     SYS     READ     NO     NO

  • Problem in using UTL_FILE.FOPEN with filename containing accent characters

    select value from nls_database_parameters where parameter = 'NLS_CHARACTERSET';
    VALUE
    AL32UTF8
    declare
    l_output UTL_FILE.FILE_TYPE;
    filename varchar2(100) := 'Avenue des Champs-Élysées.txt';
    begin
    l_output := UTL_FILE.FOPEN ('UPLOAD_DIR', filename, 'W');
    utl_file.put_line (l_output, 'Testing');
    utl_file.fclose(l_output);
    end;
    The file in the UPLOAD_DIR becomes "Avenue des Champs-Élysées.txt"
    can anyone tell me what NLS settings I should use in order to create file with correct filename ?

    symplik wrote:
    The file in the UPLOAD_DIR becomes "Avenue des Champs-Élysées.txt"And what does the o/s file system support and what is the operating system's NLS settings?
    If there is a mismatch between what you do in your code in Oracle, and what the o/s is configured for, then this type of "+translation+" error is to be expected.

  • Cannot create a file using  UTL_FILE.FOPEN

    Dear All,
    I am using this syntax for creating a file in window
    i have declare this like this
    l_file_id UTL_FILE.file_type;
    l_file_name := 'DHL_'||110570284||'_'||TO_CHAR(SYSDATE,'ddmmyyyy')||'.txt'
    l_file_id :=UTL_FILE.FOPEN('C:\D2R',l_file_name,'W');
    Is this syntax work?
    My database version is oralce 10g
    Thanks

    First of all, UTL_FILE is PL/SQL package and is executed on database server side, not on client side. Therefore, it is trying to create file in directory C:\D2R on database sefrver. So if you want to create file in directory C:\D2R on your client box - you can't. Next point - you are specifying directory explicitly which old and obsolete syntax. It requires, for security reasons to add C:\D2R to init.ora parameter UTL_FILE_DIR, otherwise UTL_FILE will raise an error. You should use directory objects:
    CREATE DIRECTORY dir AS 'C:\D2R';and grant READ/WRITE on it to users. Then use:
    l_file_id :=UTL_FILE.FOPEN('DIR',l_file_name,'W'); -- use directory name in upper caseAnd keep in mind, as I already mentioned UTL_FILE is PL/SQL package and is executed on database server side which means it runs under OS user oracle. Therefore OS user oracle must have write permission on C:\D2R.
    SY.

  • Unable to create file using : =utl_file.fopen

    Hi Team,
    My issue is file is not getting created, i checked the permissions of the directory.
    No error is received while executing the below script .
    declare
    f1 utl_file.file_type;
    begin
    f1:=utl_file.fopen('TAX_CODE_OUT_FILE_PATH','test.txt','W');
    utl_file.put_line(f1,'memocan');
    utl_file.fclose(f1);
    end;
    Any suggestion why file is not getting created ?

    i tried the following :
    declare
    V1 VARCHAR2(32767);
    f1 utl_file.file_type;
    begin
    F1 := UTL_FILE.FOPEN('TAX_CODE_OUT_FILE_PATH','in.txt','R');
    UTL_FILE.GET_LINE(F1,V1,32767);
    UTL_FILE.FCLOSE(F1);
    end;
    Error is thrown as following ;
    Error report:
    ORA-29283: invalid file operation
    ORA-06512: at "SYS.UTL_FILE", line 537
    ORA-29283: invalid file operation
    ORA-06512: at line 6
    29283. 00000 - "invalid file operation"
    *Cause:    An attempt was made to read from a file or directory that does
    not exist, or file or directory access was denied by the
    operating system.
    *Action:   Verify file and directory access privileges on the file system,
    and if reading, verify that the file exists.
    Any suggestions ??

  • Error while using UTL_FILE

    I am getting the following error while using UTL_FILE procedure while using UTL_FILE.FOPEN procedure
    from system account. I am using Windows XP with NTFS.
    SQL> create or replace directory FILE_DIR as 'C:\'
    2 /
    Directory created.
    SQL> grant read on directory FILE_DIR to public;
    Grant succeeded.
    1 create or replace PROCEDURE file_upload IS
    2 v_file_name VARCHAR2(200);
    3 v_file_type UTL_FILE.FILE_TYPE;
    4 v_line VARCHAR2(1000);
    5 BEGIN
    6 v_file_name := 'customers_'||TO_CHAR(SYSDATE,'dd')||TO_CHAR(SYSDATE,'MON')||TO_CHAR(SYSDATE,'YYYY')||'.txt';
    7 v_file_type := UTL_FILE.FOPEN('FILE_DIR','V_FILE_NAME','r',1000);
    8 UTL_FILE.GET_LINE(v_file_type,V_LINE,1000);
    9 UTL_FILE.FCLOSE(v_file_type);
    10 DBMS_OUTPUT.PUT_LINE(V_LINE);
    11* END;
    SQL> exec file_upload;
    BEGIN file_upload; END;
    ERROR at line 1:
    ORA-29283: invalid file operation
    ORA-06512: at "SYS.UTL_FILE", line 475
    ORA-29283: invalid file operation
    ORA-06512: at "SYSTEM.FILE_UPLOAD", line 7
    ORA-06512: at line 1
    I appreciate if someone can help me in this regard.
    Thanks in Advance.
    Regards
    Muhammad ALi

    Hello,
    What exactly are you trying to do? Here I got 2 examples for you , replace with your directory name and pick right option for 'a' (append) or 'w' (write) or 'R' (read).
    To read from a directory_ . This will read an existing file 'customer.txt" from the directory
    {code}
    CREATE OR REPLACE PROCEDURE .file_upload
    IS
    v_file_name VARCHAR2 (200);
    v_file_type UTL_FILE.file_type;
    v_line VARCHAR2 (1000);
    BEGIN
    v_file_name := 'customers.txt';
    v_file_type := UTL_FILE.fopen ('EXT_TABLES', v_file_name, 'R');
    UTL_FILE.get_line (v_file_type, v_line); -- Error was here
    DBMS_OUTPUT.put_line (v_line);
    UTL_FILE.fclose (v_file_type);
    END;
    {code}
    _*To open a file*_ This will create customer_XXXXX file under the directory
    {code}
    CREATE OR REPLACE PROCEDURE testme.file_upload
    IS
    v_file_name VARCHAR2 (200);
    v_file_type UTL_FILE.file_type;
    v_line VARCHAR2 (1000);
    BEGIN
    v_file_name := 'customers_'
    || TO_CHAR (SYSDATE, 'dd')
    || TO_CHAR (SYSDATE, 'MON')
    || TO_CHAR (SYSDATE, 'YYYY')
    || '.txt';
    v_file_type := UTL_FILE.fopen ('EXT_TABLES', v_file_name, 'a');
    UTL_FILE.put_line (v_file_type, v_line);
    DBMS_OUTPUT.put_line (v_line);
    UTL_FILE.fclose (v_file_type);
    END;
    {code}
    Regards
    Edited by: OrionNet on Jan 29, 2009 12:30 AM

  • UTL_FILE.FOPEN in PL/SQL

    Hi,
    I want to use UTL_FILE.FOPEN in PL/SQL procedure. I keep getting an exception when I try to open the file.
    FDebug := UTL_FILE.FOPEN('D:\SQL', 'debug.txt', 'w');
    UTL_FILE.PUT_LINE(FDebug, 'Hello World');
    UTL_FILE.FCLOSE(FDebug);
    I believe the problem is that the directory is inaccessible.
    I read in another post that the UTL_FILE_DIR must be set in the init.ora file. However, I do not have an init.ora file. I am willing to add one but do not know how.
    Any help would be aprreciated.
    Thank You,
    Scott
    null

    Up to 8i, Oracle refused to access a file that is not pointed to in the utl_file_dir parameter in the init<sid>.ora file.
    In Oracle 9i, in order to access a file, either the utl_file_dir parameter must be set, or one has to create a directory as create or replace directory dir_temp as 'c:\temp';

  • Issue while accessing a file using UTL_FILE

    Hi,
    My requirement is to check for the existence of a file in the file system(apps tier) and then launch a conc program to load the data.
    There is a separate DB tier.
    I am trying to use UTL_FILE.fopen to indirectly see if the file exists
    and then proceed and I am trying to use UTL_FILE.fopen for that.
    The file is placed in the apps tier. I have created a directory in the database with the path and using that in the UTL_FILE.FOPEN call.
    However I am getting the following error. ORA-29283 - An attempt was made to read from a file or directory that does not exist, or file or directory access was denied by the operating system.
    What could be the issue here? Is there anything that I need to do after creating the directory?.
    Thanks,
    Balaji

    /Pl post details of OS, database and EBS versions.
    Are the Apps and DB servers physically separate ? If so, the directory on the Apps server where the file resides will have to be visible/updateable to the DB server in order for UTL_FILE to be able to read/write to it.
    HTH
    Srini/
    The apps and db servers are separate. EBS version is 11.5.10.2 and the OS is unix.
    How do I make the directory in apps server visible/updateable to the DB server?. I have created a directory in the database with the location of the file in apps tier.
    Thanks for your quick reply
    Regards
    Balaji

  • Load from EBCDIC file to Oracle 9i tables using UTL_FILE

    Hello, I have a requirement to load EBCDIC file from Mainframe to load to Oracle 9i tables and then do some transformation. Then again create EBCDIC file from database table. I'm not sure if this is possible using UTL_FILE, though i have seen people loading using SQL * Loader. If possible, can you please give some sample code for this? I would appreciate your help
    Thanks
    Karuna

    Hi,
    I'm reading data from EBCDIC file in Oracle PL/SQL using UTL_FILE. I wasn't able to read BINARY data type from EBCDIC to Oracle. Initially i thought the problem was due to the following reasons discussed in the article.
    http://support.sas.com/techsup/technote/ts642.html
    <quote>
    Solutions
    The only way to overcome the problem of non-standard numeric data being corrupted by the FTP is to move the data without translating it. This will necessitate making some significant changes in your program. It may also require preprocessing the data file on the mainframe. The sections below list the different types of files and situations, a recommended approach to read in the file, and a sample program to accomplish the task.
    </quote>
    But we have confirmed that the contents of EBCDIC file is fine by looking into the EBCDIC file using a tool that will convert EBCDIC to ASCII. The contents are absolutely ok.
    Now how do i read the Binary data from EBCDIC file.
    My code is like this...
    Open the file using UTL_FILE.FOPEN
    UTL_FILE.GET_LINE(file_handler,string,lengthofthestring)
    DBMS_OUTPUT.PUT_LINE(SUBSTR(CONVERT(string,ASCIIUS7,EBCDIC),1,4));
    --This is generating an output as "&". The actual data is
    --005. Since this is
    --declared as binary in EBCDIC file, I'm unable to read
    --and print it.
    --same is the case with other binary data types.
    --I'm able to read the other datatypes clearly
    UTL_FILE.FCLOSE.
    How do I resolve this? I would appreciate your help on this. This is something critical and immediate requirement for us.
    Thanks
    Karuna

  • Why this error in writing string to text file using utl_file?

    HI Friends,
    Iam trying to write procedure to add one line of text in text file using UTIL package. But getting error.
    create or replace procedure Add_To_File() is
    OutFile utl_file.file_type;
    l_err_code NUMBER(10);
    l_err_msg VARCHAR2(2000);
    vNewLine VARCHAR2(4000);
    vdir varchar2(200):='UTIL_DIR';
    begin
    OutFile:=utl_file.fopen(vdir,'out.txt','w','32000');
    vNewLine:='Loading is successfull';
    utl_file.put_line(OutFile,vNewLine);
    EXCEPTION
    WHEN OTHERS THEN
    l_err_code := SQLCODE;
    l_err_msg := SUBSTR(SQLERRM,1,128);
    Dbms_output.put_line(l_err_code || l_err_msg);
    end;
    when i execute above procedure iam getting this error.
    LINE/COL ERROR
    1/23 PLS-00103: Encountered the symbol ")" when expecting one of the
    following:
    <an identifier> <a double-quoted delimited-identifier>
    current delete exists prior
    Please suggest me where iam wrong.
    Thanks,
    Venkat Vadlamudi

    868591 wrote:
    HI Friends,
    Iam trying to write procedure to add one line of text in text file using UTIL package. But getting error.
    create or replace procedure Add_To_File() is
    OutFile utl_file.file_type;
    l_err_code NUMBER(10);
    l_err_msg VARCHAR2(2000);
    vNewLine VARCHAR2(4000);
    vdir varchar2(200):='UTIL_DIR';
    begin
    OutFile:=utl_file.fopen(vdir,'out.txt','w','32000');
    vNewLine:='Loading is successfull';
    utl_file.put_line(OutFile,vNewLine);
    EXCEPTION
    WHEN OTHERS THEN
    l_err_code := SQLCODE;
    l_err_msg := SUBSTR(SQLERRM,1,128);
    Dbms_output.put_line(l_err_code || l_err_msg);
    end;
    when i execute above procedure iam getting this error.
    LINE/COL ERROR
    1/23 PLS-00103: Encountered the symbol ")" when expecting one of the
    following:
    <an identifier> <a double-quoted delimited-identifier>
    current delete exists prior
    Please suggest me where iam wrong.
    Thanks,
    Venkat Vadlamudibelow works for me
      1  CREATE OR replace PROCEDURE Add_to_file
      2  IS
      3    outfile       utl_file.file_type;
      4    l_err_code NUMBER(10);
      5    l_err_msg  VARCHAR2(2000);
      6    vnewline   VARCHAR2(4000);
      7    vdir       VARCHAR2(200) := 'UTIL_DIR';
      8  BEGIN
      9    outfile := utl_file.Fopen(vdir, 'out.txt', 'w', '32000');
    10    vnewline := 'Loading is successfull';
    11    utl_file.Put_line(outfile, vnewline);
    12  EXCEPTION
    13    WHEN OTHERS THEN
    14            l_err_code := SQLCODE;
    15            l_err_msg := Substr(sqlerrm, 1, 128);
    16            dbms_output.Put_line(l_err_code
    17                           || l_err_msg);
    18* END;
    SQL> /
    Procedure created.

  • Problem Using UTL_FILE package ORA-29285

    Dear All,
    I would very much appreciate your help.
    I am trying to export data form a table.
    The version of the DB is 10.2.0.4
    I am using the following procedure:
    create or replace
    procedure EXPORT_FRAME(
    dir IN VARCHAR2, filename IN VARCHAR2) IS
    f utl_file.file_type;
      cursor frame is
        Select *
        from test_complete_frame_2008;
    begin
      f:= utl_file.fopen (dir, filename,'w');
      FOR a IN frame
      Loop
        utl_file.put_line (f,
            '"'||a.COM_DATA_ID || '";"' ||
               a.COM_DATA_SET_ID || '";"'||
                a.NSI || '";"'||
                a.FRAME_ID || '";"'||
                a.STATUS_FRAME || '";"'||
                TO_CHAR(a.FRAME_REFERENCE_DATE, 'dd/mm/yyyy') || '";"'||
                TO_CHAR(a.DATE_OF_SELECTION, 'dd/mm/yyyy')  || '";'||
                a.EU_LEU_ID || ';"'||
                a.NSA_ID || '";"'||
                a.SOURCE_IDENTITY || '";"'||
                TO_CHAR(a.REF_DATE_LEU_IDENTITY, 'dd/mm/yyyy') || '";"'||
                a.NATIONAL_ID || '";"'||
                a.REF_DATE_NATIONAL_ID || '";"'||
                a.DUNS_NUMBER || '";"'||
                TO_CHAR(a.REF_DATE_DUNS_NUMBER, 'dd/mm/yyyy') || '";"'||
                a.BVD_ID || '";"'||
                TO_CHAR(a.REF_DATE_BVD_ID, 'dd/mm/yyyy') || '";"'||
                a.NAME_LEGAL_UNIT || '";"'||
                a.LEGAL_FORM_EGR || '";"'||
                a.SOURCE_LEGAL_FORM || '";"'||
                TO_CHAR(a.REF_DATE_LEGAL_FORM, 'dd/mm/yyyy') || '";"'||
                a.TYPE_OF_LEGAL_UNIT || '";"'||
                a.SOURCE_CODE_TYPE_OF_LEU || '";"'||
                TO_CHAR(a.REF_DATE_TYPE_OF_LEU, 'dd/mm/yyyy') || '";"'||
                a.STATUS_LEU || '";"'||
                a.SOURCE_CODE_STATUS_LEU || '";"'||
                TO_CHAR(a.REF_DATE_STATUS_LEU, 'dd/mm/yyyy') || '";"'||
                a.POST_DELIVERY_POINT || '";"'||
                a.CITY_NAME || '";"'||
                a.POSTAL_CODE || '";"'||
                a.STATE_NAME || '";"'||
                a.COUNTRY_CODE_BOP || '";"'||
                a.COUNTRY_ACCESS_CODE || '";"'||
                a.TELEPHONE_NUMBER || '";"'||
                a.FAX_NUMBER || '";"'||
                TO_CHAR(a.DATE_OF_INCORPORATE, 'dd/mm/yyyy') || '";"'||
                a.SOURCE_DATE_OF_INCORP || '";"'||
                TO_CHAR(a.REF_DATE_DATE_OF_INCORP, 'dd/mm/yyyy') || '";"'||
                TO_CHAR(a.DATE_OF_LIQUIDATION, 'dd/mm/yyyy') || '";"'||
                a.SOURCE_DATE_OF_LIQ || '";"'||
                TO_CHAR(a.REF_DATE_DATE_OF_LIQ, 'dd/mm/yyyy') || '";"'||
                a.NACE_CODE || '";"'||
                a.VERSION_NACE || '";"'||
                a.SOURCE_CODE_NACE || '";"'||
                TO_CHAR(a.REF_DATE_NACE, 'dd/mm/yyyy') || '";"'||
                a.NUMBER_PERS_EMPLOYED || '";"'||
                a.SOURCE_CODE_PERS_EMPL || '";"'||
                a.CONS_PERSON_EMPLOYED || '";"'||
                TO_CHAR(a.REF_DATE_PERS_EMPLOYED, 'dd/mm/yyyy') || '";"'||
                a.SPECIAL_PURP_ENTITY_CODE || '";"'||
                a.SOURCE_CODE_SPE || '";"'||
                TO_CHAR(a.REF_DATE_SPE_CODE, 'dd/mm/yyyy') || '";"'||
                a.EMAIL_ADDRESS || '";"'||
                TO_CHAR(a.REF_DATE_EMAIL_ADDRESS, 'dd/mm/yyyy') || '";"'||
                a.WEB_ADDRESS || '";"'||
                TO_CHAR(a.REF_DATE_WEB_ADDRESS, 'dd/mm/yyyy') || '";"'||
                a.P_EU_LEU_ID || '";"'||
                a.P_NAME_LEGAL_UNIT || '";"'||
                a.P_COUNTRY_CODE_BOP || '";"'||
                a.STATUS_RELATIONSHIP || '";"'||
                a.PERCENTAGE || '";"'||
                a.KIND_OF_CONTROL || '";"'||
                a.SOURCE_CODE_RELATIONSHIP || '";"'||
                TO_CHAR(a.REF_DATE_RELATIONSHIP, 'dd/mm/yyyy') || '";"'||
                a.GLOBAL_LEVEL || '";"'||
                a.GGH_EU_LEU_ID || '";"'||
                a.GGH_NAME_LEGAL_UNIT || '";"'||
                a.GGH_COUNTRY_CODE_BOP || '";"'||
                a.GGH_NSA_ID || '";"'||
                a.GGH_DUNS_NUMBER || '";"'||
                a.GGH_BVD_ID || '";"'||
                a.GGH_SOURCE_IDENTITY || '";"'||
                a.GLOBAL_EG_ID || '";"'||
                a.GLOBAL_EG_NAME || '";"'||
                a.TOP_MNE_IND || '";"'||
                a.GEG_PERSONS_EMPLOYED || '";"'||
                a.GEG_SOURCE_CODE_PERS_EMPL || '";"'||
                TO_CHAR(a.GEG_REF_DATE_PERS_EMPL, 'dd/mm/yyyy') || '";"'||
                a.NUMBER_OF_LEGAL_UNITS || '";"'||
                a.GEG_NACE_CODE_DIV || '";"'||
                a.GEG_SOURCE_CODE_NACE || '";"'||
                TO_CHAR(a.GEG_REF_DATE_NACE, 'dd/mm/yyyy') || '";"'||
                a.GEG_CONS_TURNOVER || '";"'||
                a.GEG_VALUTA_CONS_TURNOVER || '";"'||
                TO_CHAR(a.GEG_BEGIN_CONS_TURNOVER, 'dd/mm/yyyy') || '";"'||
                TO_CHAR(a.GEG_END_CONS_TURNOVER, 'dd/mm/yyyy') || '";"'||
                a.GEG_SOURCE_CONS_TURNOVER || '";"'||
                TO_CHAR(a.GEG_REF_DATE_C_TURNOVER, 'dd/mm/yyyy') || '";"'||
                a.GEG_TOTAL_ASSETS || '";"'||
                a.GEG_VALUTA_TOTAL_ASSETS || '";"'||
                a.GEG_SOURCE_TOTAL_ASSETS || '";"'||
                TO_CHAR(a.GEG_REF_DATE_TOTAL_ASSETS, 'dd/mm/yyyy') || '";"'||
                a.GEG_WEB_ADDRESS || '";"'||
                a.GDC_EU_LEU_ID || '";"'||
                a.GDC_NAME_LEGAL_UNIT || '";"'||
                a.GDC_COUNTRY_CODE_BOP || '";"'||
                a.GDC_NSA_ID || '";"'||
                a.GDC_DUNS_NUMBER || '";"'||
                a.GDC_BVD_ID || '";"'||
                a.GDC_SOURCE_IDENTITY || '";"'||
                a.REP_EU_LEU_ID || '";"'||
                a.REP_NAME_LEGAL_UNIT || '";"'||
                a.REP_POST_DELIVERY_POINT || '";"'||
                a.REP_POSTAL_CODE || '";"'||
                a.REP_STATE_NAME || '";"'||
                a.REP_CITY_NAME || '";"'||
                a.REP_COUNTRY_CODE_BOP || '"'
           UTL_FILE.new_line (f);
      END LOOP;
      UTL_FILE.new_line (f);
      UTL_FILE.fclose(f);
        EXCEPTION
          WHEN NO_DATA_FOUND
            THEN dbms_output.put_line ('FAILED');
    END EXPORT_FRAME;I get an error message:
    Error starting at line 1 in command:
    begin EXPORT_FRAME ('EXP','test2.csv'); end;
    Error report:
    ORA-29285: file write error
    ORA-06512: at "SYS.UTL_FILE", line 136
    ORA-06512: at "SYS.UTL_FILE", line 813
    ORA-06512: at "EGR.EXPORT_FRAME", line 13
    ORA-06512: at line 1
    29285. 00000 - "file write error"
    *Cause:    Failed to write to, flush, or close a file.
    *Action:   Verify that the file exists, that it is accessible, and that
    it is open in write or append mode.
    Any idea?
    Thanks in advance!

    By default UTL_FILE.FOPEN opens file with record size up to 1024 characters (including newline). Most likely your code exceeds 1024. Change:
    f:= utl_file.fopen (dir, filename,'w');to something like (assuming none of your records will exceed 10000)
    f:= utl_file.fopen (dir, filename,'w',10000);SY.

  • Runtime error using utl_file package

    Hi Friends,
    This is the procedure for reading sample data from flat file , but it won't work.
    create or replace procedure test_utl_file
    is
    ftype utl_file.file_type;
    ch varchar2(200);
    begin
    ftype := utl_file.FOPEN('C:\oracle\temp','data.txt,R');
    utl_file.get_line(ftype,ch);
    dbms_output.put_line(ch);
    end;
    This code is compiled succesfully , but at runtime it shows an error msg
    ORA-29280: invalid directory path
    ORA-06512: at "SYS.UTL_FILE", line 33
    ORA-06512: at "SYS.UTL_FILE", line 436
    ORA-06512: at "SCOTT.TEST_UTL_FILE", line 7
    ORA-06512: at line 1
    I had entered the directory entry in int.ora file
    utl_file_dir=C:\oracle\temp
    & i used another way also,
    by using alter set utl_file_dir=C:\oracle\temp scope=spfile;
    Can anyone help me to resolve this problem.
    Rgrds,
    Anand

    What database version are you using?
    The UTL_FILE_DIR parameter has been deprecated by oracle in favour of direcory objects because of it's security problems.
    The correct thing to do is to create a directory object e.g.:
    CREATE OR REPLACE DIRECTORY mydir AS 'c:\myfiles';
    Note: This does not create the directory on the file system. You have to do that yourself and ensure that oracle has permission to read/write to that file system directory.
    Then, grant permission to the users who require access e.g....
    GRANT READ,WRITE ON DIRECTORY mydir TO myuser;
    Then use that directory object inside your FOPEN statement e.g.
    fh := UTL_FILE.FOPEN('MYDIR', 'myfile.txt', 'r');
    Note: You MUST specify the directory object name in quotes and in UPPER case for this to work as it is a string that is referring to a database object name which will have been stored in uppercase by default.

Maybe you are looking for

  • How to Collapse Tracks in Arrange Window?

    I've been searching this and some other forums, and have a feeling I'm outta luck, but figured I should post a question here before writing up another Feature Request... Separate from the Hide Track function (which isn't quite what I'm wanting), and

  • When trying to open pages 08 file with pages 09

    I am trying to open an old pages08 document using pages 09 however is not letting me do so.  A message saying " to open it save it as pages09 first" is coming up however I cannot even open the file, how can I save it as pages 09 then? Very frustratin

  • How can I tell if an executable is already running?

    I'm writing a rather large LabWindows/CVI program, and occasionally will triple-click on the desktop icon, starting two copies of it. Is there some way to tell if a program is already running, so that the second copy can shut itself off? Solved! Go t

  • I changed my apple ID and lost everything. How do I get all my apps and purchased items back?

    I changed my apple ID and lost everything. How do I get all my apps and purchased items back?

  • IPhoto thumbnail query

    Hi, when using iPhoto (08 version 7.1.5.(378)) a box popped up advising me that there was a new thumb nail format for iPhoto available so I clicked ok. Ive since lost all my named/dated photo albums in iPhoto BUT the individual photos are still store