Reg : txt Files in Server directory (UTL_FILE)

Hi Experts,
Suppose, I've placed 5 +.txt+ files (procedure/table creation scripts) in a db server directory.
Is there any way I can loop through each of the files?
I need to pull the content of each file into oracle table using a procedure. So, I'm trying dynamically trying to use External Tables with Execute Immediate inside my proc. Will package UTL_FILE help in this?
Please give some suggestions.
Let me know if you have any concerns.
Ranit B.

As an alternative solution, have you considered using external LOB's? Using this approach could save significant overhead vs. the external tables solution because it doesn't require any schema objects for accessing the txt files (if you use an SQL script instead of a stored procedure).
http://docs.oracle.com/cd/B14117_01/appdev.101/b10796/adlob_bf.htm#1010878
Below is an excerpt from the link the Oracle docs above; this could be used as a starting point. (Substitute your directory name/file name for the BFILENAME arguments.)
/* This file is installed in the following path when you install */
/* the database: $ORACLE_HOME/rdbms/demo/lobs/plsql/fdisplay.sql */
/* Displaying BFILE data.  */
/* Procedure displayBFILE_proc is not part of DBMS_LOB package: */
CREATE OR REPLACE PROCEDURE displayBFILE_proc IS
   file_loc BFILE := BFILENAME('MEDIA_DIR', 'monitor_3060.txt');
   Buffer   RAW(1024);
   Amount   BINARY_INTEGER := 200;
   Position INTEGER        := 1;
BEGIN
   DBMS_OUTPUT.PUT_LINE('------------ BFILE DISPLAY EXAMPLE ------------');
   /* Opening the BFILE: */
   DBMS_LOB.OPEN (file_loc, DBMS_LOB.LOB_READONLY);
   LOOP
      DBMS_LOB.READ (file_loc, Amount, Position, Buffer);
      /* Display the buffer contents: */
      DBMS_OUTPUT.PUT_LINE(substr(utl_raw.cast_to_varchar2(Buffer), 1, 250));
      Position := Position + Amount;
   END LOOP;
   /* Closing the BFILE: */
   DBMS_LOB.CLOSE (file_loc);
   EXCEPTION
   WHEN NO_DATA_FOUND THEN
      DBMS_OUTPUT.PUT_LINE('End of data');
END;
SHOW ERRORS;

Similar Messages

  • # At the end of record in .txt file on server

    I am reading a .txt file on server ..
    Spliting the recoed at horizantal tab.
    everything is fine but the # at the and of record is not getting eliminated.
    I have tried with CR_LF and NEWLINE tooo ... no use....
    I have to be able to delete this..

    Hi Kalyan Mohan Venigalla,
    if you open dataset in text mode and read dataset into <textvar or string>, the linefeeds should not be read but used to distinguish lines of (possible) different line length.
    The # character just means non-displayable character. Depending on where the file comes from and how it was created and/or transfered to SAP server, this may be anything.
    In debugger, you may switch to hex view and see what it is. Compare to the attributes of CL_ABAP_CHAR_UTILITIES and choose the right one for deletion or replacement.
    Regards,
    Clemens

  • Find The Txt Files in root directory

    Iin Sql if we want to check a text fiile in root directory (D:\windows\commands\dil.txt) exists or not what is right way or right command for it
    Thanks in Advance

    Oracle beginner wrote:
    utl_file.fgetattr('D:\windows\commands\', 'dil.txt', ex, flen, bsize);Wrong. Common mistake in thinking that the directory can be specified like that. It cannot. *+
    Oracle does not allow direct access to server directories as this will be a security violation.
    Instead, Oracle allows you to define a directory object that refers to a specific server directory. Once defined, read and write access on this object can be granted to schemas.
    This then provides a security mechanism - requiring PL/SQL code to use a directory object and have access (read and/or write) to the object.
    Secondly, it also support abstraction of the actual physical directory path. For example, the application code can use the directory object CSV_FILES - and the actual location can be implementation specific and differ from the mainframe Oracle server, to the Unix Oracle server to the Windows Oracle server.
    Details on FGETATTR are in [Oracle® Database PL/SQL Packages and Types Reference|http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/u_file.htm#i1003488] guide.
    * Please note that the old style utl_file_dir parameter has been discontinued in Oracle and its use is not recommended by Oracle and constitutes a pretty serious security violation if used.

  • Java code to upload file and place file on server directory

    Hi,
    Am a relatively new Java programmer. I need to add a functionality to a struts web application to allow users UPLOAD a file (using browse button). I need to read the file name,, do some other checks and eventually, upload the file to a server directory.
    When do I start? Any good website for source code examples?
    Thanks

    See this http://jakarta.apache.org/commons/fileupload/

  • Issues loading .txt files from server...

    Hi.
    I have an issue with a script I created that loads text strings from a file on my server.
    The swf file loads a message from a .txt file, displays it in an animation when the animation finishes it loops back to the start and loads the next message and displays it in the animation.
    All works fine. However the script reads the text file from the server on every loop ( 3 seconds ) This will be hard on my server so... Is there a way to read the text file once only and then loop through the eight statements?
    Thanks. Z
    Actionscript 2. Flash CS3. Flash Player 10.
    quotes.txt - text file containing eight quotes
    quote_txt - Dynamic field within animation
    ranQuote = new LoadVars();
    ranQuote.onLoad = function(success) {
        if (success) {
            RanNum = RanNum+1;
            if (RanNum>=9) {
                RanNum = 1;
                ran = this["quote"+(RanNum)];
                quote_txt.text = ran;
            } else {
                ran = this["quote"+RanNum];
                quote_txt.text = ran;
        } else {
            quote_txt.text = "Display if can't load txt file";
    ranQuote.load("quotes.txt");

    Unless I'm missing something, each time you load the file you are loading the entire file.  So you should have all of what's in it stored.  Your load function appears to just be picking out one of them out randomly after they're all loaded.
    I assumed wrongly that this isn't all the code you have and other loading code is what you are trying to inhibit.
    What you probably want to do is take most of your onLoad code and place it into a function.  What you have that is pulling up the quotes should utilize that function.  You shouldn't be using that loading code each time some button or whatever loop cycles.

  • How to read LARGE .TXT FILES from server

    i m unable to read large .txt (>100kb) files from server.
    also is there any way to store the content in mobile phone.
    PLEASE HELP as iam in dire need and only few days are left.
    thanks

    Hi
    > i m unable to read large .txt (>100kb) files from server.
    What do you mean by that? Are you trying to display that amount of text and you get an error. Are you trying to read from the server and you get there an error?
    > also is there any way to store the content in mobile phone.
    Using RMS. But be aware of the size limit specific to every phone.
    Mihai

  • Problems with moving files to ora directory UTL_FILE.PUT_RAW - ORA-29285

    hi,
    i'm using apex 4.1
    i have a procedure which moves my file from apex_application_files to ORA directory.
    if i choose a text file or small word document which is 1kb, it works. but if i have pdf file (85kb) or word document (16kb) it gives me ORA-29285: file write error
    what's my problem?
    PROCEDURE put_file_to_server (p_filename IN VARCHAR2,p_cert_type IN VARCHAR2,p_cert_pk IN NUMBER)
    AS
    l_file UTL_FILE.file_type;
    l_blob_len INTEGER;
    l_pos INTEGER := 1;
    l_amount BINARY_INTEGER := 32767;
    l_buffer RAW (32767);
    v_new_filename VARCHAR2(100);
    v_bfile BFILE ;
    BEGIN
    -- delete from apex_application_files;
    --Neuen Dateinamen generieren
    v_new_filename := p_cert_type||'_'||p_cert_pk;
    v_bfile := BFILENAME (v_directory, v_new_filename);
    --Datei erstellen
    l_file := UTL_FILE.fopen(v_directory,v_new_filename,'w');
    IF DBMS_LOB.FILEEXISTS (v_bfile) = 1 THEN
    cert_log_pkg.m(p_module => 'CERT_FILE_PKG.PUT_FILE_TO_SERVER',p_msg => 'File exists');
    FOR rec IN (select blob_content lblob from apex_application_files where rownum = 1)
    LOOP
    l_blob_len := DBMS_LOB.getlength(rec.lblob);
    cert_log_pkg.m(p_module => 'CERT_FILE_PKG.PUT_FILE_TO_SERVER',p_msg => 'Filesize is '||l_blob_len);
    WHILE l_pos < l_blob_len LOOP
    DBMS_LOB.read (rec.lblob, l_amount, l_pos, l_buffer);
    UTL_FILE.put_raw (l_file, l_buffer, FALSE);
    l_pos := l_pos + l_amount;
    END LOOP;
    COMMIT;
    END LOOP;
    --Datei schließen
    UTL_FILE.fclose(l_file);
    else
    cert_log_pkg.m(p_module => 'CERT_FILE_PKG.PUT_FILE_TO_SERVER',p_msg => 'Datei doesn't exist');
    end if;
    EXCEPTION
    WHEN OTHERS
    THEN
    -- Close the file if something goes wrong.
    IF UTL_FILE.is_open (l_file) THEN
    UTL_FILE.fclose (l_file);
    END IF;
    delete from apex_application_files;
    RAISE;
    delete from apex_application_files;
    END put_file_to_server;

    Sorry but din't test this...Can you give it a try and see if this works?
    PROCEDURE put_file_to_server(
        p_filename  IN VARCHAR2,
        p_cert_type IN VARCHAR2,
        p_cert_pk   IN NUMBER)
    AS
      l_file UTL_FILE.file_type;
      l_blob_len INTEGER;
      l_pos      INTEGER      := 1;
      l_amount BINARY_INTEGER := 32767;
      l_buffer RAW (32767);
      v_new_filename VARCHAR2(100);
      v_bfile BFILE ;
      vblob BLOB;
      vstart NUMBER := 1;
      my_vr RAW(32000);
      bytelen NUMBER := 32000;
      LEN     NUMBER;
    BEGIN
      -- delete from apex_application_files;
      --Neuen Dateinamen generieren
      v_new_filename := p_cert_type||'_'||p_cert_pk;
      v_bfile        := BFILENAME (v_directory, v_new_filename);
      --Datei erstellen
      --l_file                          := UTL_FILE.fopen(v_directory,v_new_filename,'w');
      l_file                          := UTL_FILE.fopen(v_directory,v_new_filename, 'WB', 32760);
      IF DBMS_LOB.FILEEXISTS (v_bfile) = 1 THEN
        cert_log_pkg.m(p_module => 'CERT_FILE_PKG.PUT_FILE_TO_SERVER',p_msg => 'File exists');
        FOR rec IN
        (SELECT blob_content lblob,
          LENGTH(blob_content) LEN
        FROM apex_application_files
        WHERE rownum = 1
        LOOP
          cert_log_pkg.m(p_module => 'CERT_FILE_PKG.PUT_FILE_TO_SERVER',p_msg => 'Filesize is '|| LEN);
          IF LEN < 32760 THEN
            utl_file.put_raw(l_file,lblob);
            utl_file.fflush(l_file);
          ELSE -- write in pieces
            vstart      := 1;
            WHILE vstart < LEN
            LOOP
              dbms_lob.read(vblob,bytelen,vstart,my_vr);
              utl_file.put_raw(l_file,my_vr);
              utl_file.fflush(l_file);
              -- set the start position for the next cut
              vstart := vstart + bytelen;
              -- set the end position if less than 32000 bytes
              x         := x - bytelen;
              IF x       < 32000 THEN
                bytelen := x;
              END IF;
            END LOOP;
          END IF;
         END LOOP;
        ELSE
          cert_log_pkg.m(p_module => 'CERT_FILE_PKG.PUT_FILE_TO_SERVER',p_msg => 'Datei doesnt exist');
        END IF;
        utl_file.fclose(l_file);
      EXCEPTION
      WHEN OTHERS THEN
        -- Close the file if something goes wrong.
        IF UTL_FILE.is_open (l_file) THEN
          UTL_FILE.fclose (l_file);
        END IF;
        DELETE FROM apex_application_files;
        RAISE;
        DELETE FROM apex_application_files;
      END put_file_to_server;Edited by: Vitor Rodrigues on 17/Fev/2012 12:03

  • Move files from server to client

    I have create txt file in server directory using UTL_FILE package,
    and I put in the directory in server.
    Server platform is linux. and client platform in Windows.
    What I want to ask is there any possibilities to copy that file from server to client using pl/sql ? could all of you "The Gurus" give me a script example ?
    Thanks a lot.
    regards,
    indra

    > What I want to ask is there any possibilities to copy that file from server
    to client using pl/sql
    No. Not really.
    Think about it.. the file is on the server. PL/SQL code executes inside the Oracle server session that is servicing the client.
    Just how is PL/SQL (on the server) suppose to reach out and push that file to a client's file system and directory?
    PL/SQL cannot do this. You need something on the client that will accept the file. You need something in-between the client and PL/SQL that will handle the transfer of the file. This something can be ftp, scp, tftp, NetBIOS etc.
    Anyway you look at this, it does not make sense. You are turning the server into the client that needs to push the file. You are turning the client into a server that needs to accept the file.
    Why? This is contrary to the basic client-server RDBMS architecture. You are adding more complexities and more moving parts to the architecture by forcing a swap of client and server roles. The are now a far greater likelihood of errors and bugs and failures.
    It does not make sense to do it this way.
    What is the business requirement you are trying to satisfy? Instead of us trying to help you to hack a flawed solution, let us rather assist you in determining the correct and proper solution.

  • How to check whether the Application Server directory exits or not

    Hi,
    I have a selection screen in which I give the Application server file name(UNIX file) as input. Here, I would like to check whether the Server directory exists or not.
    Let us say, the path I gave in the selection screen is /usr/sap/tmp/testfile.txt . Here, the file name is testfile.txt and the server directory is /usr/sap/tmp . I would like to check whether this directory /usr/sap/tmp exists in the server or not. I am not bothered about the file name as I am going to write data into the file. I am mainly concerned about whether the directory exists in the server or not. and one more thing... this is the Application Server path not the Local path.
    Can anyone help me on the same how to check whether the server directory exists or not.
    Thanks in advance.
    Best Regards,
    Pradeep.

    Also you can use the FM EPS_GET_DIRECTORY_LISTING for this purpose.
      Store the directory name
        l_dpath = p_file+0(l_no).
      Validate the directory of the application server
        CALL FUNCTION 'EPS_GET_DIRECTORY_LISTING'
          EXPORTING
            dir_name               = l_dpath
          TABLES
            dir_list               = l_i_dlist
          EXCEPTIONS
            invalid_eps_subdir     = 1
            sapgparam_failed       = 2
            build_directory_failed = 3
            no_authorization       = 4
            read_directory_failed  = 5
            too_many_read_errors   = 6
            empty_directory_list   = 7
            OTHERS                 = 8.
      If any problem occurs with the directory then display proper
      error message
        IF sy-subrc <> 0.
        Display error message
          MESSAGE e018 WITH 'Problem with directory entered'(008).
        ENDIF. " sy-subrc <> 0
    Regards,
    Joy.

  • How do i delete Older files from the directory before create a new file?

    Hi,
    How do i delete older files in a particular directory,
    the senorio is count the number of .txt files in a directory and delete the older files if file count is more than 10. (if i add 11th file the very first file has to be deleted)
    i have written the code to count the files and delete , but it is deleting all the files instead of older file
    public class ExtensionFilter implements FilenameFilter {
      private String extension;
      public ExtensionFilter( String extension ) {
        this.extension = extension;            
      public boolean accept(File dir, String name) {
        return (name.endsWith(extension));
    public class FileUtils{
      public static void main(String args[]) throws Exception {
        FileUtils.deleteFiles("c:/countfile/", ".txt");
      public static void deleteFiles( String directory, String extension ) {
        ExtensionFilter filter = new ExtensionFilter(extension);
        File dir = new File(directory);
        String[] list = dir.list(filter);
        File file;
        if (list.length == 0) return;
        for (int i = 0; i < list.length; i++) {
          //file = new File(directory + list);
    file = new File(directory, list[i]);
    if ((list[i]).length()>=10)
         System.out.print(file + " deleted : " + file.delete());
    Thanks,
    Jamin Rosina                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    What your code is doing now, is deleting all filenames that are longer than 10 characters.
    Your problem lies in the line:
    if ((list).length()>=10)

  • FTP Adapter not writing the file in FTP directory

    We have desiged BPEL Process which will get data from Oracle and write in txt file in FTP directory.
    For last few days, we are getting following error when we invoke the BPEL Process:
    file:/u102/product/10.1.3.1/OracleAS_1/bpel/domains/default/tmp/.bpel_XXADS_INT033_DEL_EBS_OUT_1.0_0be42a99260084d9bd5104929a8ac1b2.tmp/DELFTPservice.
    wsdl [ Put_ptt::Put(opaque) ] - WSIF JCA Execute of operation 'Put' failed due
    to: Error saving control file.
    Error saving control file: "/u102/product/10.1.3.1/OracleAS_1/j2ee/home/fileftp/controlFiles/ZmbNdvlpVkaee+
    OddQzH2Q==/outbound/controlFile_ob.properties"
    ; nested exception is:
    ORABPEL-11080
    Error saving control file.
    Error saving control file: "/u102/product/10.1.3.1/OracleAS_1/j2ee/home/fileftp/controlFiles/ZmbNdvlpVkaee+
    OddQzH2Q==/outbound/controlFile_ob.properties"
    Please make sure that a valid control file exists.
    Can anyone help me to resolve this?
    Thanks,
    Hariharan Ramakrishnan

    I tried to redo the config objects but still the same issue is there. anyone has any idea

  • How do i merge all the files in a directory into a single file

    I need to merge(or move) all the files(all are .txt files) in a directory into a single file?

    Thanks Martin, but I was searching for an inbuilt class or a stream like the SequenceInput class that could do this for me.

  • How to read a file on specific  Directory

    How to read a specific file on specific folder ,
    For ex , in D: contain lot of directory ,
    Let as assume �program �- Directory.
    �xxx.txt�-file,
    How to read �xxx.txt� file from program Directory,
    Give me simple pgm ,

    pradeep.rajadurai wrote:
    How to read a specific file on specific folder ,
    For ex , in D: contain lot of directory ,
    Let as assume �program �- Directory.
    �xxx.txt�-file,
    How to read �xxx.txt� file from program Directory,
    Give me simple pgm ,
    Scanner scan = new Scanner(new File("D:/program/xxx.txt"));
    // your code here[http://java.sun.com/j2se/1.5.0/docs/api/java/util/Scanner.html]

  • Need to copy .txt file from FTP server and downloaded on local server directory.

    I need to figure out a way to copy .txt file from ftp server in local server directory using sql jobs.

    Below links will help achieving it:
    https://www.virtualobjectives.com.au/sqlserver/ftp_scripts.htm
    http://www.mssqltips.com/sqlservertip/2884/sql-server-integration-services-ssis-ftp-task-for-data-exchange/

  • Reg. PDF file stored in oracle server directory

    Dear All ,
    How to stored PDF generated file in oracle server directory.
    Thanks & Regards
    shailesh

    You need a directory object in Oracle for that server directory. That directory needs to be accessible (permission/ACL wise) to the local database processes to read/write from/
    The schema that will be doing the read/write using that directory object, needs read/write privs on it.
    UTL_FILE is used by PL/SQL code to write database contents to file.

Maybe you are looking for

  • How to see "all files" in an Acrobat folder?

    Before the last update, when opening a folder in Acrobat XI there was an option arrow for document type, show .pdf files or "Show all files."  That option does not seem to be there any longer

  • Updated to 7.6.1.9 and now MOST songs cannot find their path!!!!!!!!!!!!!!

    I'm about ready to scream. I updated iTunes to the 7.6.1.9 version and now when I tried to synch my iPod it gave me a message that stated it cannot find some songs. When I look at my iTunes it has and exclamation point next to the MAJORITY of my 5,00

  • Dynamic SQL Statement with table name

    Dear all i like to have a SQL statement with a dynamic tablename. Is this possible? If yes, how? should be something like "select * from <mytablename>" Thank you Herbert

  • Need sum help..........Regarding Oracle Procedure Builder

    hi, i wnt sum information abt oracle procedure builder. i m preparing for 1zo-047,n wnt oracle procedure builder 2 practice. cn ne1 plssssssssssss tel me whr shd i luk 4 it.... i cd nt found dis s/z newhr on internet,i even dnt knw whether i hv 2 dow

  • Preparatory workflow for image gallery

    I would like advice about what tools might be available in DW CS4 to help with the preparations for an image gallery. I have settled on a page design with the artist and processed about 150 images for a gallery. These need to be categorised according