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

Similar Messages

  • Fire up a copy thread when the new file added to the directory

    Hello,
    I am writing a thread to copy the files from a specific directory to the server. Since the files are sent to this directory by another group and I want to do the coping whenever the files are in the directory.
    Could you tell me how I can monitor the files in the directory and fire up the copy thread when the files are there?
    Thanks in advance!
    David

    Guess you can use a thread to check the directory for any changes and, if found, do the copying. You can use the same thread you used to copy for checking as well.

  • 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

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

  • 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

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

  • 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 can I copy layers from one .fla file to another .fla file?

    Hi,
    How can I copy layers from one .fla file to another .fla file? Please do help.
    Thanks.

    Select all the frames you want to copy, right click and select copy frames then select the file you want to paste them into and right click again and then paste frames.
    The layers the frames are should come across with them.

  • Error while copying a file from windows oracle server to a solaris server

    Hi all,
    DECLARE
      l_conn  UTL_TCP.connection;
    BEGIN
      l_conn := ftp.login('Destination Ip address ', '22', 'Username', 'Password');
      ftp.ascii(p_conn => l_conn);
      ftp.put(p_conn      => l_conn,
              p_from_dir  => 'MID5010_DOC1TEMP', -- Oracle Directory name from where we need to copy a file
              p_from_file => 'Hipaa.33KM.5093.06152011130146885.834.O.irl',
              p_to_file   => '/qatest1/mihipaa5010/mj5010/DevelopmentStage/working_directory/Outbound/Data/75061252/Hipaa.00AN.07262011173844778.820.O.copied.irl'); -- Directory of the destination machine where we need to paste
      ftp.logout(l_conn);    
       exception
        when others then
          dbms_output.put_line(sqlcode || sqlerrm);
          --dbms_output.put_line(l_conn);    
    END;We are getting the below error:
    SSH-1.99-OpenSSH_5.1
    -29260ORA-29260: network error: TNS:connection closed
    Could any one please let us know why this error is raising...

    prakash wrote:
    Hi all,
    DECLARE
    l_conn  UTL_TCP.connection;
    BEGIN
    l_conn := ftp.login('Destination Ip address ', '22', 'Username', 'Password');
    ftp.ascii(p_conn => l_conn);
    ftp.put(p_conn      => l_conn,
    p_from_dir  => 'MID5010_DOC1TEMP', -- Oracle Directory name from where we need to copy a file
    p_from_file => 'Hipaa.33KM.5093.06152011130146885.834.O.irl',
    p_to_file   => '/qatest1/mihipaa5010/mj5010/DevelopmentStage/working_directory/Outbound/Data/75061252/Hipaa.00AN.07262011173844778.820.O.copied.irl'); -- Directory of the destination machine where we need to paste
    ftp.logout(l_conn);    
    exception
    when others then
    dbms_output.put_line(sqlcode || sqlerrm);
    --dbms_output.put_line(l_conn);    
    END;We are getting the below error:
    SSH-1.99-OpenSSH_5.1
    -29260ORA-29260: network error: TNS:connection closed
    Could any one please let us know why this error is raising...As sybrand correctly points out, this issue doesn't belong here.
    You are using a 3rd party package "ftp" and the error it is indicating suggests the issue is a network issue of some sort.
    We don't have the code of that package or know what it is doing, so please consult whoever supplied or wrote the package and/or your network administrators.

  • Copying music failed. The file name was invalid or too long.

    I went to consolidate my music, but when it got about 2/3 of the way through, it stopped with the error message, "Copying music failed. The file name was invalid or too long." I don't know which file it is referring to. How do I find this out?
    I needed to cosolidate so I could backup the entire library to DVD. Now I'm left with two partially complete libraries with many duplicates.

    To find out which file it was, look at where you were
    copying them too and see which was the last file
    copied - and then go back to your source, and go to
    the next one - it should be that one.
    I just wanted to add that I had the same issue (failure to finish copying and "invalid or too long" error msg) and at first didn't see how looking for the last file copied would work since iTunes is copying into folders.
    Duh.
    Reverse sort by date modified (newest folder at the top of the list) then drill down to the folder containing the files being copied. Voila. There was the (missing) culprit, and I knew which file to rename in the source folder.
    Thanks for the kick in the brain pan.
    Sony VAIO PCG-V505ACP Windows XP Pro

  • Copying Large Blocks of MP3 files from External Hard Drive to iTunes

    I'm trying to copy large numbers of MP3 files from my external
    hard drive to iTunes. I tried putting them in the iTunes music folder but this did not work. Then I tried selecting blocks of the songs and dragging and dropping them in iTunes. This also did not work because when I select a large block of files and then click on them (holding down the mouse button) to drag them, then they become "unselected." So, I guess my question is 2 fold: Why can I not copy and paste these files to some folder on the Macintosh Hard drive where they will be recognized by iTunes (show up in iTunes) and what is wrong with my clicking and dragging technique? Am I losing it?

    If you are trying to add tunes to your library then do the work from within iTunes not via the Finder. Droping the tunes into the iTunes folder will not create a reference for iTunes to find the tunes. You should be able to drag-drop the tunes/folders into the main iTunes window.
    It is usually easier to use the 'keep' and 'copy' features selected. This way iTunes will keep your tunes organized and all in one place. If you work from in the iTunes interface then you will likely not go wrong.
    From the iTunes File menu select 'add to library' (+O) and navigate to your ext HD and iTunes should bring those tunes into your library.
    MJ

  • I had made a copy of the main revel file on my mac, and then i put it in my google drive folder for safety. I accidentally deleted one of the two libraries form my iPhone. I opened it up and panicked and thankfully I guess I had a backup of the other libr

    I had made a copy of the main revel file on my mac, and then i put it in my google drive folder for safety. I accidentally deleted one of the two libraries form my iPhone. I opened it up and panicked and thankfully I guess I had a backup of the other library in my spouses phone... but mine is still gone. I don't have them saved to my computer... the pictures are important and I really really need them back.  Is there a way for me to get the pictures back from what I believed at the time was a smart way to backup when i made a duplicate of that main mac file to my google drive? The best way to let me know is my email... [email protected]  I am really relying on you guys if there is a way?

    Hi meghage,
    From your code, it is a WebForm project.
    This forum is to discuss problems of Windows Forms. Your question is not related to the topic of this forum.
    You can consider posting it in asp.net forum for supports . Thanks.
    ASP.NET: http://forums.asp.net
    Regards,
    Youjun Tang
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • I have an iMac 2013 running OSX 10.9.4. I want to use Carbon Copy Cloner to backup user files to an external hard drive. Then I want to remove iPhoto libraries from iMac. What will happen to the iPhoto libraries that I back up when I run backup in a

    I have an iMac 2013 running OSX 10.9.4. I want to use Carbon Copy Cloner to backup user files to an external hard drive to free up space on my iMack Hard drive.
    So, say I make the backup today, delete iphoto libraries from my iMac, and then backup my iMac in a week. What happens to the iphoto libraries that are on the external backup drive now that I am backing up the iMac where they no longer exist?
    I will have them backed up to a separate second external drive as well.
    I'm just very cautious about removing them from the hard drive.
    Thanks for helping and understanding my crazy caution!

    I'd like to store my Aperture /IMovie Libraries on an external hard drive.
    That is fine and recommended.. use the fastest disk you can afford.. ie Thunderbolt>USB3>FW800>USB2.
    In addition, I'd like to partition the external hard drive so that Time Machine can use it to both back up my IMac and the external library drives.
    Let me be clear.. you want to partition the one disk.. use it for TM and move your files to the external disk.. and then backup to the same disk.. You can do it.. but that is not a backup.. that is an experiment in how long you can get away with running files and backups on the same disk before you lose everything.. like Russian Roulette.. pull the trigger enough times and laws of probability will do you in.
    You must have backups on a different disk .. otherwise it is pointless.
    Can I set up a RAID 5 format for redundancy?
    No.. you can buy special USB and Thunderbolt external drives that support RAID..
    BUT that is still not a backup.. let me show why.. you make a silly move and corrupt your file in aperture.. it is not that rare.
    Raid will corrupt all copies of the files.. it is replicated across all disks.
    Delete a photo it is deleted across all disks.. you have no recovery.
    Alway, always consider RAID system one disk.. backup onto another disk.. and if the photos or movies are at all important to you.. ie your family .. make another copy and store in a relatives house.. There is no such thing as too much redundancy.

Maybe you are looking for