Write a cursor  using UTL-FILE

Hi ,
i have a flat file (ffile,txt) like this in unix sserver(i know the dir ):
No:100,200,300.
Name:dan,bob,greg.
Dep:IT,BT,MAN,CT.
every line was ended with Dot(.) for line separation.
I want a cursor like this select * from emp where eno IN( '100','200','300') and ename IN ('dan','bob',greg') AND Dept IN('IT','BT','MAN','CT');
i opened a file likethis
f1 utl_file.file_type;
f1 := utl_file.fopen('Interfae',' ffile.txt',300);
any body plz help me for build a cursor.
Thanks
satya

After re-read your question I think I got a solution with UTL_FILE, I think I didn't understood the question at the beginning.
Here is a small example, but you need to change it to your needs:
SQL> declare
  2      numbers   varchar2 (32767);
  3      names     varchar2 (32767);
  4      deptos    varchar2 (32767);
  5      f1        utl_file.file_type;
  6 
  7      cursor employees (v_numbers in varchar2) is
  8          select empno, ename, deptno
  9            from emp
10      /* the following subquery do the IN VARLIST
11      you need to add for each one you want*/
12           where empno in (
13                     select     substr (txt
14                                       , instr (txt, ',', 1, level) + 1
15                                       ,   instr (txt, ',', 1, level + 1)
16                                         - instr (txt, ',', 1, level)
17                                         - 1) as token
18                           from (select ',' || v_numbers || ',' txt
19                                   from dual)
20                     connect by level <=
21                                      length (v_numbers)
22                                    - length (replace (v_numbers, ',', '') )
23                                    + 1);
24  begin
25      f1 := utl_file.fopen ('TEMP_DIR', 'TEST_DATA.TXT', 'R');
26      utl_file.get_line (f1, numbers);
27      utl_file.get_line (f1, names);
28      utl_file.get_line (f1, deptos);
29      utl_file.fclose (f1);
30  
31   dbms_output.put_line ('============Values from the file===========');
32      dbms_output.put_line (numbers);
33      dbms_output.put_line (names);
34      dbms_output.put_line (deptos);
35 
36      dbms_output.put_line ('===== Doing the cursor with the IN values from the file ===');
37   for v_emp in employees (substr (numbers, 4) ) loop
38          dbms_output.put_line (   v_emp.empno
39                                || '-'
40                                || v_emp.ename
41                                || '-'
42                                || v_emp.deptno);
43      end loop;
44  end;
45  /
============Values from the file===========
No:7369,7499,7521
name:jones,martin,blake
depno:20,30,10
===== Doing the cursor with the IN values from the file ===
7369-SMITH-20
7521-WARD-30
7499-ALLEN-30
PL/SQL procedure successfully completed.I think the complicated part for that is the VAR INLIST, you can user Tom's function examples if you don't want to use the long query option, like in your case you will be using several of them.
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:210612357425
I'm doing several assumptions here, like 3 lines in the file, the first "part" of the first line is "No:",etc.
Message was edited by:
Delfino Nunez

Similar Messages

  • Error using UTL File

    Hi,
    I am using UTL file to export data to an external file and getting an error which i am unable to reslove... Can anyone help me with this
    SQL> create or replace
    2 procedure MEXICO_NAFTA_CERTIFICATE_EXT (
    3 f_org_id varchar2,
    4 f_customer_nbr_base varchar2,
    5 f_customer_nbr_sufx varchar2,
    6 f_year VARCHAR2)
    7 is
    8 output_file utl_file.file_type;
    9 o_filename VARCHAR2(50):= 'MEXICO_NAFTA_CERTIFICATE_EXT.txt';
    10 o_DataDir CONSTANT VARCHAR2 (30) := '/d014/oradata/temp';
    11 v_CERTIFICATE_NBR fta.SAP_CERTIFICATES_EXTRACT_VIEW.CERTIFICATE_NBR%type;
    12 v_PART171 fta.SAP_CERTIFICATES_EXTRACT_VIEW.PART171%type;
    13 v_INACTIVE_IND fta.SAP_CERTIFICATES_EXTRACT_VIEW.INACTIVE_IND%type;
    14 v_HTS_CDE fta.SAP_CERTIFICATES_EXTRACT_VIEW.HTS_CDE%type;
    15 v_ORIGINATING_IND fta.SAP_CERTIFICATES_EXTRACT_VIEW.ORIGINATING_IND%type;
    16 v_ISO_COUNTRY_CDE fta.SAP_CERTIFICATES_EXTRACT_VIEW.ISO_COUNTRY_CDE%type;
    17 v_BASIS_CDE fta.SAP_CERTIFICATES_EXTRACT_VIEW.BASIS_CDE%type;
    18 v_PRODUCER_CDE fta.SAP_CERTIFICATES_EXTRACT_VIEW.PRODUCER_CDE%type;
    19 v_CERT_CDE fta.SAP_CERTIFICATES_EXTRACT_VIEW.CERT_CDE%type;
    20 v_REGIONAL_VALUE_CONTENT_CDE fta.SAP_CERTIFICATES_EXTRACT_VIEW.REGIONAL_VALUE_CONTENT_CDE%type;
    21 v_PART_NBR fta.SAP_CERTIFICATES_EXTRACT_VIEW.PART_NBR%type;
    22 v_EFFECTIVE_DATE fta.SAP_CERTIFICATES_EXTRACT_VIEW.EFFECTIVE_DATE%type;
    23 v_EFFECTIVE_FROM_DATE fta.SAP_CERTIFICATES_EXTRACT_VIEW.EFFECTIVE_FROM_DATE%type;
    24 v_EFFECTIVE_TO_DATE fta.SAP_CERTIFICATES_EXTRACT_VIEW.EFFECTIVE_TO_DATE%type;
    25 v_TRANSACTION_DATE fta.SAP_CERTIFICATES_EXTRACT_VIEW.TRANSACTION_DATE%type;
    26
    27
    28 CURSOR Cert_ext IS select certificate_nbr ,
    29 part171,
    30 inactive_ind,
    31 hts_cde,
    32 originating_ind,
    33 iso_country_cde,
    34 basis_cde,
    35 producer_cde,
    36 cert_cde,
    37 regional_value_content_cde,
    38 part_nbr,
    39 effective_date,
    40 effective_from_date,
    41 effective_to_date,
    42 transaction_date
    43 from fta.SAP_CERTIFICATES_EXTRACT_VIEW
    44 where org_id= f_org_id AND
    45 customer_nbr_base= f_customer_nbr_base AND
    46 customer_nbr_sufx = f_customer_nbr_sufx AND
    47 to_char(effective_from_date, 'yy') = f_year AND
    48 to_char(effective_to_date, 'yy') = f_year;
    49
    50 begin
    51
    52 output_File := UTL_FILE.FOPEN (o_DataDir, o_FileName, 'w');
    53
    54 OPEN Cert_ext;
    55 loop
    56
    57 fetch Cert_ext into v_CERTIFICATE_NBR ,
    58 v_PART171 ,
    59 v_INACTIVE_IND,
    60 v_HTS_CDE ,
    61 v_ORIGINATING_IND ,
    62 v_ISO_COUNTRY_CDE ,
    63 v_BASIS_CDE ,
    64 v_PRODUCER_CDE ,
    65 v_CERT_CDE ,
    66 v_REGIONAL_VALUE_CONTENT_CDE ,
    67 v_PART_NBR,
    68 v_effective_date,
    69 v_effective_from_date,
    70 v_effective_to_date,
    71 v_transaction_date ;
    72
    73 UTL_FILE.PUT_LINE (output_File, v_CERTIFICATE_NBR || ' '||
    74 v_PART171 || ' '||
    75 v_INACTIVE_IND || ' '||
    76 v_HTS_CDE || ' '||
    77 v_ORIGINATING_IND || ' '||
    78 v_ISO_COUNTRY_CDE || ' '||
    79 v_BASIS_CDE || ' '||
    80 v_PRODUCER_CDE || ' '||
    81 v_CERT_CDE || ' '||
    82 v_REGIONAL_VALUE_CONTENT_CDE || ' '||
    83 v_PART_NBR || ' '||
    84 to_char(v_EFFECTIVE_DATE, 'mm-dd-yy') || ' '||
    85 to_char(v_EFFECTIVE_FROM_DATE, 'mm-dd-yy') || ' '||
    86 to_char(v_EFFECTIVE_TO_DATE, 'mm-dd-yy') || ' '||
    87 to_char(v_TRANSACTION_DATE, 'mm-dd-yy'));
    88
    89 UTL_FILE.FCLOSE (output_File);
    90 DBMS_OUTPUT.PUT_LINE ('Data Extracted');
    91 end loop;
    92 close Cert_ext;
    93 END MEXICO_NAFTA_CERTIFICATE_EXT;
    94 /
    Procedure created.
    SQL> declare
    2 begin
    3 MEXICO_NAFTA_CERTIFICATE_EXT('0048', '00254101', '11', '03');
    4 end;
    5 /
    Data Extracted
    declare
    ERROR at line 1:
    ORA-29282: invalid file ID
    ORA-06512: at "SYS.UTL_FILE", line 774
    ORA-06512: at "FTA_SOURCE.MEXICO_NAFTA_CERTIFICATE_EXT", line 72
    ORA-06512: at line 3

    what is the datatype of your column org_id for the table fta.SAP_CERTIFICATES_EXTRACT_VIEW? also try to put this exceptions to see what might be the exact cause of the error.
      EXCEPTION
        WHEN utl_file.invalid_mode THEN
          RAISE_APPLICATION_ERROR (-20051, 'Invalid Mode Parameter');
        WHEN utl_file.invalid_path THEN
          RAISE_APPLICATION_ERROR (-20052, 'Invalid File Location');
        WHEN utl_file.invalid_filehandle THEN
          RAISE_APPLICATION_ERROR (-20053, 'Invalid Filehandle');
        WHEN utl_file.invalid_operation THEN
          RAISE_APPLICATION_ERROR (-20054, 'Invalid Operation');
        WHEN utl_file.read_error THEN
          RAISE_APPLICATION_ERROR (-20055, 'Read Error');
        WHEN utl_file.internal_error THEN
          RAISE_APPLICATION_ERROR (-20057, 'Internal Error');
        WHEN utl_file.charsetmismatch THEN
          RAISE_APPLICATION_ERROR (-20058, 'Opened With FOPEN_NCHAR But Later I/O Inconsistent');
        WHEN utl_file.file_open THEN
          RAISE_APPLICATION_ERROR (-20059, 'File Already Opened');
        WHEN utl_file.invalid_maxlinesize THEN
          RAISE_APPLICATION_ERROR(-20060,'Line Size Exceeds 32K');
        WHEN utl_file.invalid_filename THEN
          RAISE_APPLICATION_ERROR (-20061, 'Invalid File Name');
        WHEN utl_file.access_denied THEN
          RAISE_APPLICATION_ERROR (-20062, 'File Access Denied By');
        WHEN utl_file.invalid_offset THEN
          RAISE_APPLICATION_ERROR (-20063,'FSEEK Param Less Than 0');
        WHEN others THEN
          RAISE_APPLICATION_ERROR (-20099, 'Unknown UTL_FILE Error');

  • How can i create  excel sheet with multiple tabs using utl file?

    how can i create excel sheet with multiple tabs using utl file?
    any one help me?

    Jaggy,
    I gave you the most suitable answer on your own thread yesterday
    Re: How to Generating Excel workbook with multiple worksheets

  • Getting error while using UTL files

    hi All,
    I'm getting following error -
    ORA-29282: invalid file ID ORA-06512: at "SYS.UTL_FILE", line 774 ORA-06512: at "IMPORT_NEW", line 781 ORA-01722: invalid number
    To used UTL i have done following steps -
    1. created directory
    2. grant read, write to that directory from sys
    but every time I'm getting above error.
    Can any one tell me, where am I going wrong?
    Subir

    here is the basic code...
    CREATE OR REPLACE PROCEDURE import_new
    begin
    logfilename :=
    'DnB_Source_'
    || datasetversionid
    || '-'
    || TO_CHAR (SYSDATE, 'YYMMDDHH24MI')
    || '.log';
    vsfile := UTL_FILE.fopen ('import_LOG', logfilename, 'w');
    UTL_FILE.put_line
    (vsfile,
    'No treatments have been done, Data are already in Source area.'
    UTL_FILE.put_line (vsfile, '');
    UTL_FILE.put_line (vsfile,
    'Run began on '
    || TO_CHAR (beginrun, 'DAY MON DD HH24:MI:SS')
    UTL_FILE.put_line (vsfile,
    'Run ended on '
    || TO_CHAR (endrun, 'DAY MON DD HH24:MI:SS')
    UTL_FILE.fclose (vsfile);
    exection
    END import_dnb_new

  • Getting INVALID_OPERATION  while using UTL file

    Hi,
    I have a procedure which makes different UTL files i.e data file, error file and log file for a Purchase order. These 3 sets of files are made for every purchase order.
    So suppose in a cursor i find that there are 10 Purchase orders to process, then it should create 30 UTL files 10 sets of 3 files.
    But when i run this procedure, after processing 3 PO's i.e after creating 9 files i get INVALID_OPERATION error.
    So lets say i have 10 PO's 1 to 10 , i run for first time PO 1,2 and 3 utl files are created and then i get error. Then when i run it again processes PO number 4 to 6 and then again error...
    So i want to know is there any restriction on number of UTL files you can create in a single procedure. i want urgent help, appreciate ur quick replies on this matter.
    thanks,
    Dipin

    Hi,
    There could be several reasons for this...
    1. In inti ora file, what utl file directory was specified? is it 'C:\PLXML\DBDOM'? if not check.
    2. Do u have C:\PLXML\DBDOM\Testfile.txt in your directory?
    3. If you have above file in that directory and you have opened that file for writing purpose, close that.
    Ur program looks ok. Also, dbms_output.put_line will display 255 charcters only(at least in 7.3).
    Koti.
    null

  • Can we create pdf files from oracle using UTL FILE

    i have sample code---
    create or replace procedure UTLTEST as
    f1 utl_file.file_type;
    begin
    -- Open a file in write mode
    f1 := utl_file.fopen('UTL_FILE_DIR1','NEWFILE.pdf','W');
    -- Write a line to a file
    utl_file.put_line(f1,'1. This is a test of UTL_FILE packages');
    utl_file.put_line(f1,'2. Oracle has added a new procedures in the package');
    utl_file.put_line(f1,'3. We will see all the procedure one by one');
    -- Close a file
    utl_file.fclose(f1);
    end;
    file is created but when i opened it ,it gives me error that file can not open
    is there any way to do it?

    Hi!
    you can see the following link ---
    http://forums.oracle.com/forums/search.jspa?threadID=&q=how+to+create+pdf+from+pl+sql&objID=f75&dateRange=all&userID=&numResults=15 .
    And also -- http://www.plpdf.com/ .
    Hope this will help u a bit.
    Regards.
    Satyaki De.

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

  • Flat file to tables (insert/update/delete) using utl file.--urgent

    Hi all,
    Scenorio s here ...
    ex : emp
    EMPNO
    ENAME
    JOB
    MGR
    HIREDATE
    SAL
    COMM
    DEPTNO
    STATUS -- i/U/d
    flat file records willbe like this ....
    I^001^name^job^manager^10-dec-2002^90000^900^^
    I^001^name^job^manager^10-dec-2002^90000^900^343^
    U,002^name^job^manager^10-dec-2002^90000^900^899^900
    U,002^name^job^manager^10-dec-2002^90000^900^899^900
    The first record indicator show I , so need to insert into the table emp.The second record indicator show U , so need to update the table emp.like this i've 5 tables(different structure and large data ).
    How do i upload data into concern tables using procedures using UTL_file.
    Needs to generalised the processing (for each table specific)..........
    (me right now doing this way...in a pakage with UTL_FILE using pl/sql tables,parsing the record by record ,
    storeing the values in a pl/sql table then insert/updates....)
    any sugg'n ? idea? sample code ?
    Thanx OTN members.

    Hi Ganesan,
    Hope it will help.
    Best Regards
    CREATE OR REPLACE PROCEDURE TEST_UTL
         loc_input_file                varchar2(30) ;
         loc_input_path                varchar2(30) ;
         loc_utl_file                UTL_FILE.FILE_TYPE;
         loc_get_data           varchar2(500);
    BEGIN
    loc_utl_file := UTL_FILE.FOPEN(loc_input_path, loc_input_file, R');
    BEGIN
              LOOP
    UTL_FILE.GET_LINE(loc_utl_file,loc_get_data);
    IF SUBSTR(loc_get_data,1,1) = 'I' THEN
                   INSERT INTO ..........
              --     USE SUBSTR function for columng break
              ELSIF SUBSTR(loc_get_data,1,1) = 'U' THEN
                   UPDATE ....................
              END IF;
    EXCEPTION
    WHEN NO_DATA_FOUND THEN
         UTL_FILE.FCLOSE(loc_utl_file);
    END ;
    EXCEPTION
    END;

  • Using UTL file in 10g Express Edition

    Hi,
    I have the 10g express edition and am trying to use the utl_file package.
    I have a sample script from the pl/sql oracle course that i am using to get to grips with it, however on running it i get the following error message
    4/14 PL/SQL: Item ignored
    4/14 PLS-00201: identifier 'UTL_FILE' must be declared
    the script is copied to the letter so i know its correct.
    I have added the line "UTL_FILE_DIR=*" to the init.ora file.
    I have seen some other posts that suggest its not supported on the 10gXE edition.
    Is this true?? If not, how can i get it work?
    Thanks in advance.

    Really?? cool. How do i grant privieges to it.
    I have tried grant execute on utl_file and i get the no table error.
    am assuming its a different syntax?
    G

  • Using utl files putf function

    hi
    i want to display the words like this in an .csv file
    Top 10 PCs - Good File : abc_ 20071224_051559
    Report Date: 12/24/2007
    purchase_Code,count
    i want the above three lines to be in a single column in excel file
    but it is giving in three rows
    i used the below utl_file format for the same
    UTL_FILE.PUTF
    (deltaHandle,'Top 10 PCs - Good File : abc_ %s\nReport Date: %s\nPurchase_Code,count %s\n',
    dateprefix,
    rpt_date);
    how to achieve my result
    (note: i want in the same format like
    Top 10 PCs - Good File : abc_ 20071224_051559
    Report Date: 12/24/2007
    purchase_Code,count
    but all in the same cell)
    suggestions welcome

    Try to conclude your text string into double quotes.
    e.g.
    UTL_FILE.PUTF
    (deltaHandle,'"Top 10 PCs - Good File : abc_ %s\nReport Date: %s\nPurchase_Code,count %s"\n',
    dateprefix,
    rpt_date);

  • Utl file in report

    hai all,
    I have to develop a report using utl file.
    Like when the report is given a parameter some four columns are displayed, at the same time i want to write the data in a text file in the server path /usr/tmp.
    used formula column for utl file open , putline etc.
    While running i am getting the error
    REP-1401:'cf_1formula', Fatal PL/SQL error occured.
    ORA-00600:internal error code , argument :[kghal02],[oxo],[],[],[],[],[]
    can anyone suggest me a solution for this or there is any other solution for using utl file in oracle reports.
    I am in urgent need of it.
    Thamks and regards,
    aaditya

    Make sure that the directory you use with UTL_FILE is writable. For example, if you use /abc/xyz, then both directories (abc and xyz) should be writable.

  • Cretaion of UTL.File in Oracle 10G and directory entry in Ora.ini file

    Hi,
    Kindly advise me if:
    (!) we can create a directory and log file in this directory on some other server instead of creating it in the file system of the server where the Oracle 10G database is residing?
    Created directory in Oracle using create or replace directory command.
    My package will be creating a log file using UTL.File in the above directory.
    I want to create this directory on some other server to save my log file/s. Is this possible?
    (2) Also, let me know in Oracle 10G, do we need to add the directory entry (mention above in #1) in the Ora.ini file on the Oracle 10G server?

    Hi,
    1) utl_dir are different from directory object
    2) you cannot create directory on remote server and there is no need to write directory entry on oracle init file (not ini..)
    Acr

  • UTL file exception handling oracle 11g

    We use oracle 11g
    We use UTL file and exception handling in many place. Thanks in advance.
    We have many utl program and we are writing same exception handling code ,copy and paste .
    It is possible to create new UTL exception procedure and call it.
    I am not sure how to write generic UTL exception procedure and reuse the same.
    I am learning oracle etl files method.
    Please advise.
    sample program 1 :
    DECLARE
    fileHandler UTL_FILE.FILE_TYPE;
    BEGIN
    fileHandler := UTL_FILE.FOPEN('test_dir', 'test_file.txt', 'W');
    UTL_FILE.PUTF(fileHandler, 'Writing TO a file\n');
    UTL_FILE.FCLOSE(fileHandler);
    EXCEPTION
    when utl_file.invalid_path then
    raise_application_error(-20001,
    'INVALID_PATH: File location or filename was invalid.');
    when utl_file.invalid_mode then
    raise_application_error(-20002,
    'INVALID_MODE: The open_mode parameter in FOPEN was invalid.');
    when utl_file.invalid_filehandle then
    raise_application_error(-20002,
    'INVALID_FILEHANDLE: The file handle was invalid.');
    when utl_file.invalid_operation then
    raise_application_error(-20003,
    'INVALID_OPERATION: The file could not be opened or operated on as requested.');
    when utl_file.read_error then
    raise_application_error(-20004,
    'READ_ERROR: An operating system error occurred during the read operation.');
    when utl_file.write_error then
    raise_application_error(-20005,
    'WRITE_ERROR: An operating system error occurred during the write operation.');
    when utl_file.internal_error then
    raise_application_error(-20006,
    'INTERNAL_ERROR: An unspecified error in PL/SQL.');
    when utl_file.invalid_filename then
    raise_application_error(-20010, 'The filename parameter is invalid.');
    WHEN OTHERS THEN
    IF UTL_FILE.IS_OPEN(fileHandler ) THEN
    UTL_FILE.FCLOSE (fileHandler );
    END IF;
    RAISE;
    END;
    How to write generic procedure of utl exception handling ?
    please advise.
    create or replace procedure sp_utl_exception
    begin
    when utl_file.invalid_path then
    raise_application_error(-20001,
    'INVALID_PATH: File location or filename was invalid.');
    when utl_file.invalid_mode then
    raise_application_error(-20002,
    'INVALID_MODE: The open_mode parameter in FOPEN was invalid.');
    when utl_file.invalid_filehandle then
    raise_application_error(-20002,
    'INVALID_FILEHANDLE: The file handle was invalid.');
    when utl_file.invalid_operation then
    raise_application_error(-20003,
    'INVALID_OPERATION: The file could not be opened or operated on as requested.');
    when utl_file.read_error then
    raise_application_error(-20004,
    'READ_ERROR: An operating system error occurred during the read operation.');
    when utl_file.write_error then
    raise_application_error(-20005,
    'WRITE_ERROR: An operating system error occurred during the write operation.');
    when utl_file.internal_error then
    raise_application_error(-20006,
    'INTERNAL_ERROR: An unspecified error in PL/SQL.');
    when utl_file.invalid_filename then
    raise_application_error(-20010, 'The filename parameter is invalid.');
    WHEN OTHERS THEN
    IF UTL_FILE.IS_OPEN(fileHandler ) THEN
    UTL_FILE.FCLOSE (fileHandler );
    END IF;
    RAISE;
    end;

    Mahesh Kaila wrote:
    Hello,
    Common procedure to log exception in log file
    create or replace procedure sp_utl_exception (log_dir varchar2, log_file varchar2, exception_msg varchar2)
    is
    hnd_file   UTL_FILE.file_type;
    begin
    hnd_file := UTL_FILE.fopen (log_dir, log_file, 'A');
    UTL_FILE.put_line (hnd_file, exception_msg);
    UTL_FILE.fclose (hnd_file);
    exception
    when others
    then
    raise;
    end;
    Very poor implementation.
    a) Absolutely no need for that exception handler in there. It should be removed.
    b) As it's a procedure for logging exceptions relating to UTL_FILE, it would seem error prone to be logging the errors with UTL_FILE. For example, what is it supposed to do if the exception is raised because of lack of disk space in those file locations? How is it going to write out the exception with the disk full? Also, if the exception handler is used by multiple processes, then only 1 process at a time can access the log file to write it's exceptions, so it doesn't scale well. Better logging is done by having an autonomous transaction procedure that writes log/trace messages to dedicated table(s). That also means that the logs etc. can be viewed, as appropriate, from any client using SQL (either manually or through a application written to view logs etc.), rather than requiring physical/remote access to the server o/s to go and view the contents of the file, which in itself could lock the file and prevent any process from writing further logs whilst it's being used.

  • 'Use Temporary File' in Receiver File channel

    hi all,
    I am facing a strange issue with receiver file channel which I am not sure if somene had already faced. I couldnt find any help from blogs..!
    I have configured the Receiver File channel with Write mode as  'Use Temporary File'  with a temporary file name(say tmp.xml)  scheme and Empty-Message Handling set to 'Write Empty File'
    When the scenario is executed, its so happening that the temporary file of 0 bytes(empty file) is being created as tmp<msgID>.xml before the actual file is being completely written. It is expected that once the Actual file is completely written, the tmp file should be deleted, but here is not the case.Thus causing both the files being present in the target location. This is not happening often though.
    As the receiving application is processing all files from the target direcotry, the file is getting errored out in the target application.
    I think the 'Write Empty File' has nothing to do with this as the option 'Write Empty File' is for empty payloads resulting from the message mapping.
    Please correct me if am wrong and also provide me the inputs on my issue. Am on PI7.0
    thanks in advance,

    Hi Tilak,
    this is real time interface
    real time by using a file... that's a non-sens according to me. You should use a non physical solution (web service, JMS, JDBC, etc...) but a not a file. well... Anyway, you can image that the receiver application schedule the folder every 30s or every 1min, that's almost a real time. Real time is mainly a conceptual view (only synchronous exchange needs really real time). Morevoer, if you really wanted a real time, you should not add a tool like PI (or other) between your source and your target system, the more we have systems, the less it's efficient (in term of delay and response time!).
    Even if we propose that the receiver application should have a condition to its script to avoid picking the tmp*.xml files, after a period of time there would be a chance that the *tmp files may increase in number..
    No ! coz if my theory is good, if your receiver application does not pick-up tmp.xml, that means this file is not currently treated and so PI is authorized to delete it. So no increase of tmp.xml files in this folder.
    Another solution: to create the target file without option "temporary", but to create it in another folder than this one scheduled by your receiver application, and use an OS command AFTER processing, in your receiver CC, which move the created file from the "temp" folder to the target folder.
    [http://wiki.sdn.sap.com/wiki/display/XI/SAPXIFileAdapterOSCommandLine+Feature]
    regards.
    Mickael

  • Issue with utl file

    Hi,
    I am using UTL file to export records from table with fixed delimiter to a text file.
    It works fine except that I see an additional character @ at the end of the file in the last line.
    Can anyone let me know why are we getting this and how can we delete it..
    Thaks in advance..

    I assume, as you are saying you can see the file ok in notepad/wordpad that you are creating a text file.
    So a) what are you using to view the file in unix and b) how did you transfer the file to unix?
    When you transfer files from Windows/DOS based operating systems to unix based operating systems you have to be aware that Windows uses a CR/LF pair of characters to terminate a line (a 'newline') and unix just uses a single LF character (character 10 in the ascii table) to terminate a line.  So when you transfer the files you need to convert the CR/LF pairs into just LF characters.
    Typically this is done if you transfer the files using FTP and specify the 'mode' to be ASCII rather than BINARY.
    c:\>ftp testserver
    Connected to testserver.mycompany.com.
    220 sunny2 FTP server ready.
    User (testserver.mycompany.com:(none)): myuser
    331 Password required for myuser.
    Password:
    230 User myuser logged in.
    ftp> ascii
    200 Type set to A.
    ftp>
    This tells the FTP software that you are transferring text files and that it needs to convert newline characters, if necessary, when transferring between Windows and Unix operating systems.
    And for reference, if it's not a text file, then you must transfer in BINARY mode to ensure the files remain byte for byte the same...
    ftp> bin
    200 Type set to I.
    ftp>
    If you don't transfer text files, between different operating systems, in ASCII mode, then those files will either be missing characters or have additional characters that aren't wanted.

Maybe you are looking for

  • Nothing happens when i try to open itunes 10.6.3.25

    Windows 7 - 32 bit. Absolutley nothing happens with iTunes - no error message, just nothing at all. The folder that contains the .exe file appears in Task manger as "running", but nothing happens. Have tried reinstalling etc.

  • Where do I find download only for x-Pro series for Mac?

    Hi, I ordered Acrobat X Pro (student edition for mac) but I got the  windows version instead. Help?

  • Printed document blacked out

    When printing statements from US Bank using Adobe Reader, portion of the printed documents are blacked out(redacted). US Bank said I need to make a change in Advanced setting to allow "print as image". Cannot locate the Advance button? Any help?

  • Sharing an applet with another dosn't function

    Hi all, i have a problem that i share an applet with another, but it dosn't function: i have two applet: epurse & bank   (bank is the master) for that i creat a class "bankInterface" that's inherit from sharable: package pack4; import javacard.framew

  • Unable to resize JtabbedPane..plz help

    I am sorry for asking a silly question!!.. but still because am new to java. I am using Netbeans.When i maximize the Window... JtabbedPane gets Resize in a weird Manner.i want every component to get resized Proportionately.Here r the screen shots...