Processing OS Files in an Oracle Directory

I have an application that gets XML files and stores them in a directory. I'd like to write a PL/SQL program that I can schedule to process all files in the directory. I won't know at run time what the file names are, so I need a way to somehow loop through all files in the directory, do my processing, and exit when I've run out of files.
I've been reviewing documentation and it doesn't look like fileGetName or fileExists will work for this type of processing, since they either assume a known file name or return the directory name, which I'll need to specify since there are multiple directories used by this process.
In pseudo-code, here's what I have in mind:
declare
cursor all_files is
select filename from xml_in; --xml_in is my Oracle directory where the files will live.
eachFile all_files%ROWTYPE;
begin
open all_files;
loop
fetch all_files into eachFile;
exit when all_files%NOTFOUND;
--Do my XML processing here
end loop;
close all_files;
end;
Is it possible to do this kind of processing on external files? If so, how can I get something that would function like the cursor described above to work?

The files are unknown to Oracle, I'm using an Oracle directory just as a save point for processing. I've got an external application written that will process the xml (actually, it calls an already-completed PL/SQL stored procedure) but I'd like to have portability between the different OS's.
Short answer to your question...No.

Similar Messages

  • Copying a BLOB to a File in an Oracle Directory

    Is there a straightforward way to copy a BLOB into a file in an Oracle Directory?
    The BLOB contains a binary (pdf) file.
    Thanks in advance

    Assuming you're on 9i or later, you can loop over the BLOB and use the UTL_FILE.PUT_RAW method to write out 32k chunks of the PDF at a time.
    Justin
    Forgot the link to Dan's blob2file
    http://psoug.org/reference/utl_file.html
    Message was edited by:
    Justin Cave

  • 10.1.3.4 - ESB FTP adapter not processing the files in the input directory

    I created a process that reads from a logical inputDir. I migrated the ESB service to another box and created the same adapter connection etc. however nothing really happens in this new environment. In the opmn.log i see the following statements and no other info.
    2008-12-16 14:03:41,994> <INFO> <collaxa> <ServerManager::loadProcesses> Done loading processes for all domains
    <AdapterFramework::Inbound> Instantiating inbound part of Adapter Framework instance: OraESB
    <AdapterFramework::Inbound> Adapter Framework instance: OraESB - endpointActivation for portType=Get_ptt, operation=Get
    <AdapterFramework::Inbound> Creating new instance of Resource Adapter oracle.tip.adapter.ftp.FTPResourceAdapter
    <AdapterFramework::Inbound> Adapter Framework instance: OraESB - starting Resource Adapter oracle.tip.adapter.ftp.FTPResourceAdapter
    <FTP Adapter::Inbound> File/FTP Adapter started successfully.
    <FTP Adapter::Inbound> ENDPOINT ACTIVATION CALLED IN FTP ADAPTER
    <AdapterFramework::Inbound> Adapter Framework instance: OraESB - successfully completed endpointActivation for portType=Get_ptt, operation=Get
    <FTP Adapter::Inbound> Connection Created
    <FTP Adapter::Inbound> Connection Created
    The last message "Connection Created" keeps repeating, but no processing occurs. I tried increasing all the loggers to finest. but still nothing happens.
    any idea how to troubleshoot this ? the only difference in the environment is that the new environment has 10.1.3.4 MLR2 and the first one is just plain 10.1.3.4

    Make sure that you modified the oc4j-ra.xml file in the FtpAdapter directory and have put the correct hostname and username and password. The directory structure looks like this //some-directory/oc4j_soa/application-deployments/default/FtpAdapter/oc4j-ra.xml.

  • How to find the number of files in an oracle directory through a storedproc

    hi
    i have an oracle directory or a directory in an ftp server
    is there any way.......through which..
    i can know the number of files in the directory ...?
    and whats the metadatacolumn that will indicate the name of the file?
    and is it possible to loop through each of the entries within oracle
    regards
    raj

    ops$tkyte@8i> GRANT JAVAUSERPRIV to ops$tkyte
      2  /
    Grant succeeded.
    That grant must be given to the owner of the procedure..  Allows them to read
    directories.
    ops$tkyte@8i> create global temporary table DIR_LIST
      2  ( filename varchar2(255) )
      3  on commit delete rows
      4  /
    Table created.
    ops$tkyte@8i> create or replace
      2     and compile java source named "DirList"
      3  as
      4  import java.io.*;
      5  import java.sql.*;
      6 
      7  public class DirList
      8  {
      9  public static void getList(String directory)
    10                     throws SQLException
    11  {
    12      File path = new File( directory );
    13      String[] list = path.list();
    14      String element;
    15 
    16      for(int i = 0; i < list.length; i++)
    17      {
    18          element = list;
    19 #sql { INSERT INTO DIR_LIST (FILENAME)
    20 VALUES (:element) };
    21 }
    22 }
    23
    24 }
    25 /
    Java created.
    ops$tkyte@8i>
    ops$tkyte@8i> create or replace
    2 procedure get_dir_list( p_directory in varchar2 )
    3 as language java
    4 name 'DirList.getList( java.lang.String )';
    5 /
    Procedure created.
    ops$tkyte@8i>
    ops$tkyte@8i> exec get_dir_list( '/tmp' );
    PL/SQL procedure successfully completed.
    ops$tkyte@8i> select * from dir_list where rownum < 5;
    FILENAME
    data.dat
    .rpc_door
    .pcmcia
    ps_data
    http://asktom.oracle.com/pls/asktom/f?p=100:11:4403621974400865::::P11_QUESTION_ID:439619916584
    Edited by: Salim Chelabi on 2009-04-21 10:37

  • Need to create file in unix (oracle directory path)

    Is it possible to create a file in oracle directory path (in unix folder).
    I am using a dynamic procedure to create the External Tables, when the given pattern file is present the procedure will create the External table, if the file is not present then it should create an empty file so that the corresponding External table would return zero(0) records. It should not fail.
    It has to be through plsql not using unix script.
    UTL_FILE.FGETATTR(V_DIR_NAME, V_FILE_NAME, V_EXISTS, V_FILE_LENGTH, V_BLOCKSIZE);
    IF v_exists=FALSE THEN
    --------create an empty file
    v_file_name:=empty_file;
    end if;
    --Create table script which will dynamically create the external table
    v_sql := 'CREATE TABLE '||V_RX_NAME||' ( '||RTRIM(v_cols,', ')||' )' ||
    ' ORGANIZATION EXTERNAL '||
    ' ( TYPE ORACLE_LOADER '||
    ' DEFAULT DIRECTORY "'|| v_dir_name || '"'||
    ' ACCESS PARAMETERS '||
    ' ( RECORDS DELIMITED BY NEWLINE '||
    ' LOAD WHEN ( '||RTRIM(v_null_cols,'and ')||')'||
    ' BADFILE '''||rec_mkt_name.SUBJECT_AREA_NAME||'_'||rec_mkt_name.PARAM_NAME||'.BAD''' ||
    ' DISCARDFILE '''||rec_mkt_name.SUBJECT_AREA_NAME||'_'||rec_mkt_name.PARAM_NAME||'.DISCARD''' ||
    ' LOGFILE '''||rec_mkt_name.SUBJECT_AREA_NAME||'_'||rec_mkt_name.PARAM_NAME||'.LOG'''||
    ' FIELDS TERMINATED BY ''~'' OPTIONALLY ENCLOSED BY ''"'' '||
    ' MISSING FIELD VALUES ARE NULL ' ||
    ' ) LOCATION ('''||V_FILE_NAME||''') ) REJECT LIMIT UNLIMITED';
    GV_CURR_STEP := v_sql;
    dbms_output.put_line(V_FILE_NAME) ;
    EXECUTE IMMEDIATE v_sql;
    ...........

    Saubhik wrote:
    Try to use utl_file.fopen with 'W'.Or maybe even with "A", and then close it. If you use "W" it will overwrite the file if it already exists. ;)

  • Writing a file to an Oracle Directory

    Hello,
    I'd like to use a database trigger or PL/SQL to write a text file to to a directory on my database server. Is that possible? I know I could write a daemon that runs on the OS, but I'd lie to run it from the database itself.

    OK, figured it out. This was helpful: http://www.adp-gmbh.ch/ora/sql/create_directory.html

  • Creating a text file in an oracle directory

    Hello all,
    I created a directory in oracle called sampledata (create directory sampledata as 'c:sampledata'). How do I create a new text file in that directory? That's it.
    Thanks,
    Ad

    I created a directory in oracle called sampledataYou mean you created with sys, right? I think only sys can create directories. Make sure you grant privileges to your user. So let's walk trough this:
    connect sys@orcl as sysdba;
    create or replace directory temp_directory as 'c:\temp';
    grant read, write on directory temp_directory to scott;
    connect scott@orcl;
    declare
      output_file utl_file.file_type;
    begin
        output_file := utl_file.fopen('DIR_TEMP', 'test_file.txt', 'w');
        utl_file.put_line(f, 'Testing output file');
        utl_file.fclose(output_file);
    end;
    /hth,
    gleisson henrique
    I granted priveleges to a different directory that I created. Take a look here:
    http://www.adp-gmbh.ch/ora/sql/create_directory.html
    Pretty good examples.
    Message was edited by:
    Gleisson Henrique

  • Upload a CSV file directly to an Oracle directory?

    We have some existing packaged code that reads CSV files from an Oracle directory into the database via external tables. Currently, the files are placed in the directory via FTP, but we'd like to upload them via APEX if possible.
    As far as I can tell, APEX file upload will store a file as a BLOB in an APEX table. Is there any way to re-direct the file upload to put file straight into the Oracle directory instead? The files will be copied from a Windows client to an Oracle server on Unix.
    We're still on APEX v.3.2 unfortunately.
    Edited by: chriswebster on Mar 31, 2011 10:05 AM

    >
    Similarly, we don't really want to have to extract a BLOB from the APEX file-upload table and re-create the CSV file either, as this seems like a lot of work to do a simple thing.
    >
    Not really, just a page process...
    PROCEDURE blob2file (p_blob         BLOB,
                         p_directory    VARCHAR2 := 'MY_DIR',
                         p_filename     VARCHAR2 := 'my.csv')
    IS
       t_fh    UTL_FILE.file_type;
       t_len   PLS_INTEGER := 32767;
    BEGIN
       t_fh := UTL_FILE.fopen (p_directory, p_filename, 'wb');
       FOR i IN 0 .. TRUNC ( (DBMS_LOB.getlength (p_blob) - 1) / t_len)
       LOOP
          UTL_FILE.put_raw (t_fh, DBMS_LOB.SUBSTR (p_blob, t_len, i * t_len + 1));
       END LOOP;
       UTL_FILE.fclose (t_fh);
    END;?
    Cheers
    Ben

  • How can I write more than 32k file in oracle directory

    Hi experts,
    I am struggling while I write more than 32k file size in oracle directory, and throws an error ‘ORA-06502: PL/SQL: numeric or value error, like this.
    This is my procedure
    declare
    l_s_filename   UTL_FILE.file_type;
    begin
       l_s_filename := UTL_FILE.fopen ('INFO_MIGRATION', 'finfinne.txt', 'W');
    FOR rec
          IN ( SELECT SQL_REDO
                  FROM V$LOGMNR_CONTENTS
                 WHERE seg_owner <> 'SYS' AND username = 'GENTEST'
                 AND TABLE_NAME NOT LIKE '%_TEMP'
                       AND OPERATION IN ('UPDATE','INSERT','DELETE')
              ORDER BY TIMESTAMP)
       LOOP
          UTL_FILE.put_line (l_s_filename, rec.SQL_REDO);
       END LOOP;
       UTL_FILE.fclose (l_s_filename);
    end;can any please help me how can I overcome this problem
    Thanks,
    Arun

    You can write by breaking it into small chunks. Also you can try to use DBMS_XSLPROCESSOR.CLOB2FILE. For UTL_FILE the code snippets may looks like
    -- Read chunks of the CLOB and write them to the file
    -- until complete.
       WHILE l_pos < l_blob_len
       LOOP
          DBMS_LOB.READ (rec.l_clob, l_amount, l_pos, l_buffer);
          UTL_FILE.put_line (l_file, l_buffer, FALSE);
          l_pos := l_pos + l_amount;
       END LOOP;

  • How to pass a filename dynamically in incoming email and process that file

    Hi,
    We have to process an incoming file with XI, the name of which we don't know to design time. The filename is passed dynamically in an incoming email, in the body section. We can parse the filename from the mail already. However, file adapter-sender does not accept variables (whereas receiver does), so we have no way to pass this name to the file-sender.
    What would be the best way to implement this scenario? I'd really appreciate a bit more explanation than 1-liner answers (e.g. links to help.sap.com We have SAP XI 7.0 SP15.
    TIA

    Thanks. This is similar to our plan B That is, using a wildcard, processing all files in the incoming directory, and moving them after processing. This way, only the unprocessed files would be in the source folder. IMHO, it's not elegant.
    Besides, should a second mail get received, before the first file is processed completely (e.g. due to an error, slow FTPS transfer rate, etc.), the second process would try to pick up the first file as well, which would mess up everything.
    There should be a way to set a parameter for the sender-file adapter...

  • How to Process flat File in Oracle Apps through Concurrent Program

    Hello Everyone,
    My client has a request, to process a bank file (Lockbox) which is a flat file that will be copied on UNIX box and I will have to create a new concurrent request that will process this flat file and will update receipt information in Oracle Apps database tables.
    Could you please suggest, if there are any other standard Oracle Apps functions (Example FND) available which can be used through Concurrent program that can be used to open a file from a particular directory and can be read from the flat file and after processing this file can be closed.
    Please let me know, if you have a small example, that would help me a lot.
    Thanks

    There are base concurrent programs in Accts Receivable that do consume lockbox flat files. Pl see the AR Setup/User Guides at
    http://download.oracle.com/docs/cd/B40089_10/current/html/docset.html
    Srini

  • ORA-01078: failure in processing system parameters LRM-00109: could not open parameter file '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/initORA11G.ora'

    I have installed an Oracle 11gR2 on Oracle Linux Server 6.6 (Virtualbox). I have the users grid and oracle11g. Add groups and install grid infrastructure first as a grid user and install database as oracle user as in documentation successfully.
    I have following users and groups as
    [grid@orcl11g ~]$ id grid
       uid=501(grid) gid=502(oinstall) groups=502(oinstall),492(vboxsf),501(grid),503(dba),505(asmdba),506(asmadmin),507(asmoper)
    [grid@orcl11g ~]$ id oracle11g
       uid=500(oracle11g) gid=502(oinstall) groups=502(oinstall),500(oracle11g),492(vboxsf),503(dba),504(oper),505(asmdba)
    .bash_profile edited  for oracle11g user as
    "export TMP=/tmp
    export ORACLE_HOSTNAME=orcl11g
    export ORACLE_UNQNAME=ora11g
    export ORACLE_BASE=/u01/app/oracle
    export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1
    export ORACLE_SID=ora11g
    export PATH=$PATH:$ORACLE_HOME/bin
    export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib;
    export CLASSPATH=$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib;
    .bash_profile edited  for grid user as
    "export TMP=/tmp
    export ORACLE_HOSTNAME=orcl11g
    export ORACLE_UNQNAME=+ASM
    export ORACLE_BASE=/u01/app/grid
    export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/grid
    export GRID_HOME=$ORACLE_BASE/product/11.2.0/grid
    export ORACLE_SID=+ASM
    export PATH=$PATH:$ORACLE_HOME/bin
    export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib;
    export CLASSPATH=$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib;
    When I log on as grid user. I check the followings:
    [grid@orcl11g ~]$ crsctl check has
    CRS-4638: Oracle High Availability Services is online
    [grid@orcl11g ~]$ srvctl status database -d ora11g
    Database is running.
    [grid@orcl11g ~]$ sqlplus sys as sysdba
    SQL*Plus: Release 11.2.0.1.0 Production on Thu Dec 25 19:17:37 2014
    Copyright (c) 1982, 2009, Oracle.  All rights reserved.
    Enter password:
    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    With the Automatic Storage Management option
    SQL> select status from v$instance;
    STATUS
    STARTED
    Till here everything seems to be OK!!!!
    When I log as  oracle user. I check the followings:
    [oracle11g@orcl11g ~]$ sqlplus sys as sysdba
    SQL*Plus: Release 11.2.0.1.0 Production on Thu Dec 25 19:21:46 2014
    Copyright (c) 1982, 2009, Oracle.  All rights reserved.
    Enter password:
    Connected to an idle instance.
    SQL> select status from v$instance;
    select status from v$instance
    ERROR at line 1:
    ORA-01034: ORACLE not available
    Process ID: 0
    Session ID: 0 Serial number: 0
    SQL> startup
    ORA-01078: failure in processing system parameters
    LRM-00109: could not open parameter file '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/initORA11G.ora'
    Also when I log on as a grid user again and use following commands to shutdown and start database again the STATUS of instance is again STARTED not OPEN.
    [grid@orcl11g ~]$ srvctl stop database -d ora11g -o normal
    [grid@orcl11g ~]$ srvctl start database -d ora11g
    And also when I edit /etc/oratab file. I change N to Y for +ASM. But when restart system it seems not changed value is N again.
        +ASM:/u01/app/grid/product/11.2.0/grid:N   # line added by Agent
         ora11g:/u01/app/oracle/product/11.2.0/dbhome_1:Y
    NOW QUESTIONS!!!!!
    1. Why I can't change the status of database to OPEN as grid user?
    2. The status is always STARTED when querying v$instance. İs it status of +ASM or database?
    3. When checking database as grid user it seems to be Database runnning...  If running why it is not in OPEN state? What is running means here?
    4. When I log on as oracle user and query v$instance, then error shown above occured. And also when startup  the database then another error occured as in above. WHY?
    5. When I edit /etc/oratab file manually why second row saved but the first one is changed after restart the system?
    6. Normally, which user have to start, stop or manage database? I think that oracle user is necessary for managing database and the grid user is only for managing ASM and Oracle Restart.
    PLEASE HELP ME TO SOLVE THIS CHAOTİC SİTUATİON!!!
    Thanks,
    DBA_84

    I have installed an Oracle 11gR2 on Oracle Linux Server 6.6 (Virtualbox)
    Pl identify exact version of 11gR2 to 4 decimal places. As noted in your other thread - Failed to start oracle-ohasd, error: Inappropriate ioctl for device ohasd failed to start at roothas.pl - you will need a minimum version of 11.2.0.3 for Linux 6.x - using a lower version may result in unexpected issues or problems.

  • Suggestion needed for processing Big Files in Oracle B2B

    Hi,
    We are doing a feasibility study for Using Oracle AS Integration B2B over TIBCO. We are presently using TIBCO for our B2B transactions. Now since my client company planning to Implement Fusion Middleware (Oracle ESB and Oracle BPEL), we are also looking at Oracle AS Integration B2B for B2B transactions (On other words we are planning to replace TIBCO by Oracle Integration B2B if possible).
    I am really concern about one thing that is receiving and processing any "BIG FILE" (15 MB of size) from trading partner.
    Present Scenario: One of our trading partner is sending Invoice documents in a single file and that file size can grow upto 15 MB of size. In our existing scenario when we receive such big files from trading partner (through TIBCO Business Connect - BC), Tibco BC works fine for 1 or 2 files but it crashes once it received multiple files of such size. What exactly happening is Whatever Memory that TIBCO BC is consuming to receive one such big file, are not getting released after processing and as a result TIBCO BC throws "OUT OF MEMORY" error after processing some files.
    My questions:
         1. How robust the Oracle AS Integration B2B is, in terms of processing such big files?
         2. Is there any upper limit in terms of size that Oracle AS Integration B2B can handle for receiving and processing data?
         3. What is the average time required to receive and process such big file? (Lets say we are talking about 15MB of size).
         4. Is there any documentation availble that talks about any such big files through Oracle B2B?
    Please let me know if you need more information.
    Thanks in advance.
    Regards,
    --Kaushik                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Hi Ramesh,
    Thanks for your comment. We will try to do POC ASAP. I will definitely keep in touch with you during this.
    Thanks bunch.
    Regards,
    --Kaushik                                                                                                                                                                                                                                                                                                                               

  • How to check the files ...that are present in an oracle directory

    hi all
    is there any data dictionary view or table that will list all the files that exist a oracle directory?
    regards
    raj
    we can see all the directories using dba_directories i would like to see what all files it contains
    regards
    raj

    hi justin
    this is me who posted here ..but here i was asking about... the directory that we create in oracle.....
    about dba_directories.....
    in the other post in pl/sql forum i was asking about the directory that exist on the ftp server....... and using unix from with in plsql to loop through the list of all the files
    regards
    raj

  • Error opening Oracle Directory file

    My database is Oracle 11g on Linux
    I am try to use Oracle Directory file sitting on a Windows Server.
    I am getting the following error when trying to access the file.
    ORA-29913: error in executing ODCIEXTTABLEOPEN callout
    ORA-29400: data cartridge error
    error opening file \\bbsftp01\SSH_Homes\governet/COURSE_ATTR_4891.log
    It looks like it thinks the file is sitting on a Linux server and therefore is throwing in the "/" forward slash....Can someone please help me?
    Thanks,
    Jae

    The key phrase here is
    I am try to use Oracle Directory file sitting on a Windows Server.
    Is Windows interoperable with Linux? Does Linux understand UNC?
    Don't think so and don't think so.
    Are you using Samba on the Windows Server and did you NFS mount that directory on the Linux server.
    If you didn't it is not going to work. Apart from that: Windows can deal with forward slashes so that is not the problem.
    Sybrand Bakker
    Senior Oracle DBA

Maybe you are looking for

  • How can I turn off auto-capitalization for Mail in Mountain Lion?

    How can I keep mail.app from capitalizing the first letter of sentences?  I have turned off auto-correct both at the system level and in Mail, and yet I cannot seem to keep Mail from capitalizing the first letter?

  • Truncated Data and CLOBs

    When I fetch data I'm trying to access some CLOBs as strings (i.e. when I define them I used SQLT_STR instead of SQLT_CLOB). The problem is that some of CLOBs are over 4000 bytes and 4000 is the size I get from OCI_ATTR_DATA_SIZE. Needless to say som

  • Invoke perl script from JAVA 1.4.2

    Hello All,

  • Can't find constructor

    I am trying to write a program but for some reason Java can't find my constructor public class Combinations      public void Combinations(int num1, int num2)           comb(num1, num2); }This is the error I get: Combinations.java:58: cannot find symb

  • Tuning SQL query with similar subqueries for select columns

    Hi all, My query is something like below: 1> SELECT 2> A.COL1, 3> SUM(CASE WHEN A.flag=100 AND NVL(B.flag,0)=0 AND 4> EXISTS ( 5> SELECT 'ROW_EXISTS' 6> FROM A A0 7> WHERE A0.COL2=100 AND NVL(A0.flag,0)=0 AND 0.DIRN<>A.DIRN) 8> THEN 1 9> ELSE 0 10> E