Writing multiple files using UTL_File package

Hi,
I have an requirement where I need to read the flat file and based on the first 3 character in each line which will be compared with the FlagTable, I have to create and move data into different files.
I'm using Oracle 11g in Windows xp platform.
Example:
Content of the FlatFile:
ND1T00XNDCNON0080
[email protected]
XR1 0000000179CONVERSION
PT1006 ON00014
XR195010120391231P0012 19950101 0000000179CONVERSION
ND2995010120391231a000000000000000000
XR2 0000000416PP C941995010120391231PP0012 19950101
GP206 0120391231a000
GP2061231a00000000000000 1231a0000000000000
FlagTable:
Id     Flagtype Flag
1     ND1     Y
2     ND2     Y
3     GP2     
4     XR1     Y
5     XR2     
6     PT1     
Possible output should be (duplicate files should not be created)
BP_ND1.txt
ND1T00XNDCNON0080
ND151995010120391231a0000000000000000000000000000XNDCNON0080
BP_ND2.txt
[email protected]
ND2995010120391231a000000000000000000
BP_XR1.txt
XR1 0000000179CONVERSION
XR195010120391231P0012 19950101 0000000179CONVERSION
BP.txt
PT1006 ON00014
XR2 0000000416PP C941995010120391231PP0012 19950101
GP206 0120391231a000
GP2061231a00000000000000 1231a0000000000000
Please let me know, if more info is required.
Regards,
Lokesh

How your task is related to Oracle?
This better be done with Perl or VB or whatever, but not with using RDBMS.

Similar Messages

  • 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

  • Having problem in recognising file using utl_file package..

    Hi,
    I am using utl_file utility to read the CSV file, utl_file.fopen function is useed to open file. This fopen function has three input parameters, second parameter is file name. My problem is that, i have to read file on daily basis. File name will be like:- DDMMYYYYHHMISS. Last six characters are for hour minute second of the file generation time. If the name has only DDMMYYYY then I can give the file name like TO_CHAR(SYADATE,'DDMMYYYY'), because on a particular date its same for the whole day. But hours, minutes and seconds will be of the time when the file is generated, it may be different for different days. In this condition how can I standardize the value for file name parameter in fopen function.
    Thanks in advance.

    Bharat Kaushik wrote:
    Actually.....
    I am gettting file from some other place..... And those people are not agreed to send file without exact time.JAVA solution is here
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:7506780031005
    Or if you want PL/SQL .. (May Be kiddy)
    --Please Note: SYSDATE is 26th in our DB.
    SQL> declare
      2   fp utl_file.file_type;
      3   dt date := trunc(sysdate);
      4  begin
      5   while (dt <= sysdate) loop
      6    begin
      7      fp := utl_file.fopen('OGL_REPORT_ACCESS','TEST'||to_char(dt,'ddmmyyyyhh24miss')||'.csv','r');
      8      dbms_output.put_line('TEST'||to_char(dt,'ddmmyyyyhh24miss'));
      9      utl_file.fclose(fp);
    10      exit;
    11    exception
    12     when utl_file.INVALID_OPERATION then
    13      null;
    14    end;
    15    dt := dt + 1/24/60/60;
    16   end loop;
    17  end;
    18  /
    TEST26042009010102
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:03.45
    SQL> select sysdate from dual;
    SYSDATE
    26-APR-09

  • Error while writing to file using UTL_FILE

    I've created below mentioned directory object and also granted the user appdevnew the appropriate previleges under SYSTEM user. Before giving this command, i've manually created the folder in c drive and created myspool.log file manually. Is it needed or can be created programmatically?
    CREATE DIRECTORY mydir AS 'C:\mydir';
    GRANT READ,WRITE ON DIRECTORY MYDIR TO appdevnew;
    Then logged into appdevnew and ran the block below. But i had been shown with error code ora-29280.
    DECLARE
    hnd UTL_FILE.FILE_TYPE;
    BEGIN
    hnd := UTL_FILE.FOPEN ('mydir', 'myspool.log', 'w',80);
    UTL_FILE.PUT_LINE (hnd, 'Some text here..', TRUE);
    UTL_FILE.FCLOSE (hnd);
    END;
    /

    Hi,
    It's a common problem, people think utl_file can see their PC's, whereas in fact the code runs on a server sometimes miles away and has no clue about your PC! You aren't the first and you won't be the last either.
    As for creating a directory, I take it you mean to somehow issue 'mkdir' or the equivalent to create an OS level directory (or Folder, as this is Whinedoze) on the server? You have to be careful with terminology here, because people will think (and quite rightly to) that you are referring to directory objects which utl_file now uses.
    There is no native way of doing this in PL/SQL. You can if you wish write a java stored procedure which then gives you this ability inside PL/SQL. However, I would question the need to actually dynamically create OS directories. Better do it just once for setup and be done. Less moving parts, less headaches.
    And I don't know what you mean by the file extension at all. You opened a file with the extension .log so that's what you will get. If you somehow asked utl_file to open a file called myspool.log and you ended up with myspool.txt this would be a bug and you had best log this with Oracle Support. However, if you are somehow confusing the file extension (a naming convention foisted on us by Micro$oft) with the actual contents of a file (plain text ascii or binary) then the answer is, in 9i, utl_file only gives you the abilty to write text files. Writing binary is available in 10g.
    There are workarounds to write binary files in 9i.
    HTH
    Chris
    Message was edited by:
    Chris Poole (because I can't spel)
    Message was edited by:
    Chris Poole (still can't spel)

  • 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

  • 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

  • Concatenating file using utl_file pkg.

    Hi ,
    I have files generated every 10 mins. I have to concatenate all these files for every 5 hours and distribute that file to client locations.
    can u plz. tell me is it possible to concatenate small but huge number of files
    using utl_file package.
    Help needed !!
    Thanks in advance

    Hi Guido
    Thanks for the reply ..
    But can i call this shell script from oracle procedure ...
    As i have this files in DB server and i don't have my java there ...
    I have to invoke this shell script from oracle ...

  • How to read HTML files using UTL_FILE

    Hello Friends,
    How to read HTML files using UTL_FILE package ? According
    to Oracle documentation UTL_FILE can read or write OS Text Files.
    Thanx in advance..
    Adi

    HI Hareesh,
    i have gone through that blog.
    i tried it...but i am getting mapping error  no receiver determination fond because there are so  many excel files.
    my data is available on sharedString.xml but also it is in not same order.
    i have no clue how to handle this part form the blog.
    "This way our mapping will receive all data from the sheet in an XML format. The only thing that's left is to create an XSD file from the XML file we received in order to be able to use it in the mapping and as our Service Interface and we can proceed with mapping. As you can see from the sheet.xml files all the data is placed with column name and row number so it's not that difficult to map it to an table type format using the Message Mapping only (no java, abap mapping required)."

  • Can't read text file using UTL_FILE

    Hi All,
    how can I read notepad file using UTL_FILE package.I have specified the UTL_FILE_DIR in the init.ora file.My objective is to when a button is clicked, the contents of the file will display in a text item.Here is my code written in WHEN_BUTTON_PRESSED trigger.
    DECLARE
         file_handle UTL_FILE.FILE_TYPE;
    data_line Varchar2(100);
    BEGIN
         file_handle := UTL_FILE.FOPEN('E:\vimal','abc.txt','R');
              message('directory created');
         UTL_FILE.GET_LINE(file_handle, data_line);
         :block2.t1 := data_line;
         UTL_FILE.FCLOSE(file_handle);
    END;

    Why don't you use text_io? Don't forget that UTL_FILE is reading directories from the database point of view. The E drive for the database is a different E then on your client pc. I presume your database is on a different computer. Are you getting any errors?

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

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

  • 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

  • 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

  • Unable to read the file using UTL_FILE Dir

    I need to read/write a file from/to the operating system through PLSQL Package. I used UTL_FILE package to do the same. In the application server the utl_file_dir(/usr/tmp in my system) is created as a softlink to database server.
    oI want to run this package through the application server. However I am unable to read and write the file to the operating system.
    I just wondering it is not reading/opening the file from the server. Please suggest me how to modify my code.

    Hi,
    How to check if it is end of file or not? I have the following function which is working fine in my win2003 server std 32bit and Oracle10g Database R2 Standard Edition one 32bit. HOwever, when I deploy to production server which is 64bit OS and database, it gives error at UTL_FILE.GET_LINE(fptr, tmp);
    Any idea why it behaves like that?
         FUNCTION readFile (
              inHTML OUT CLOB,
              path IN VARCHAR2,
              htmlFile IN VARCHAR2
         ) RETURN BOOLEAN IS
         fptr utl_file.file_type;
         tmp VARCHAR2(5023);
         bufferlen BINARY_INTEGER;
         BEGIN
              fptr := UTL_FILE.FOPEN(path, htmlFile, 'r');
              DBMS_LOB.CREATETEMPORARY(inHTML, TRUE);
              DBMS_LOB.OPEN(inHTML, DBMS_LOB.LOB_READWRITE);
              LOOP
                   UTL_FILE.GET_LINE(fptr, tmp);
                   if tmp is not null then
                        tmp := tmp || CHR(10);
                        bufferlen := LENGTH(tmp);
                        DBMS_LOB.WRITEAPPEND(inHTML, bufferlen, tmp);
                   end if;
              END LOOP;
              WHEN NO_DATA_FOUND THEN
              DBMS_LOB.CLOSE(inHTML);
                   UTL_FILE.FCLOSE(fptr);
                   RETURN TRUE;
              WHEN OTHERS THEN
                   DBMS_LOB.CLOSE(inHTML);
                   DBMS_LOB.FREETEMPORARY(inHTML);
                   RETURN FALSE;
         END readFile;

Maybe you are looking for

  • How can i export my video on iMovie 11?

    i have a 13 minute 1080p video that says it cannot export either because theres no room in heaping zone (which can't be right because i just bought this computer) or theres a parameter list error, i really want to export it in 1080p, how do i fix it?

  • Smartform configurations to maintain records in TFDIR

    Hi all, I need one clarification regarding Smartform. For each new smartform created, the corresponding record will be maintained in corresponding smartform relaetd tables (say : TFDIR--With FM name genarated) in SAP. But in my case it is not maintai

  • HT201272 how can I reinstall a deleted app in OSX.6.8?

    how can I reinstall a deleted app in OS 10.6.8?

  • How should a family use Ping?

    Home sharing requires that everyone in the house use the same Apple ID, so the three of us share one ID. Ping is also based off of the Apple ID. Does only one of us get to use Ping, or is there a way I haven't seen to allow personalization per indivi

  • Replace Library item sidewide in Dw

    Hi, Is there a way to change Library item sidewide in Dw? Issue: I want footer.lbi to be changed to footer-fr.lbi in a particular folder of my site. The change links sidewide command doesn't not work for this particular case as well as find/change co