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

Similar Messages

  • Error in writing to file '/u01/app/oracle/product/10.2.0/lib/libocr10.so'

    I am in middle of Oracle 10.2.0.3 pachest installation and getting this error:
    Error in writing to file '/u01/app/oracle/product/10.2.0/lib/libocr10.so'
    I shutdown database and listenter prior to start of upgarde.
    Any idea? OS AIX 5.2

    hi,
    >
    create spfile='/u01/app/oracle/product/10.2.0/db_1/dbs'
    2 from
    3 pfile='/u01/app/oracle/product/10.2.0/db_1/admin/ora/pfile/initora.ora';
    create spfile='/u01/app/oracle/product/10.2.0/db_1/dbs'
    ERROR at line 1:have you startup the database in nomount stage with pfile.. if so.
    then
    create spfile form pfile='/u01/app/oracle/product/10.2.0/db_1/admin/ora/pfile/initora.ora';
    use this command
    a spfile will be created inside /dbs/
    now restart the DB and give startup command and check the instance status..
    as mentioned above export the Oralce_home and Oracle_sid..
    regards,
    Deepak

  • 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

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

  • 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

  • Writing the file to a specific directory on server using DATASET

    Hello Friends
    I know that using dataset command we can create a file, write to a file, read from a file etc.,
    But by default it uses the directory DIR_SAPUSERS which is the ./ directory.
    But this particular directory DIR_SAPUSERS also has other system related log files etc.,
    Is there a way to make the command DATASET write to a user created directory instead of this ./ ??
    Any suggestions or comments will be highly appreciated.
    Thanks
    Ram

    IF NOT p_ufile IS INITIAL.
    OPEN DATASET p_ufile FOR INPUT IN TEXT MODE.
    IF sy-subrc <> 0.
    EXIT.
    ENDIF.
    here p_ufile will contain the path where ever u need to place the file i.e. use specific path.... ex: "usr/sap/bin/interface"

  • Writing an file to a specified directory

    I have an application in Tomcat. In this application i write data into an xml-file. When i check this, i see that the file is written in the bin directory of tomcat. Now I want to write this file into another directory, for example: /tomcat/webbaps/catalog/orders/order.xml
    Can someone tell me how my code to place it in this specified directory looks like?
    Thx !

    When you specify the file name, prefix it by the directory you want it stored in. You didn't show any code that explains how you are doing it now, so I'm not showing you any code that might be irrelevant. There are many ways to write an XML file to disk.

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

  • Error in writing to file.................................... Oracle9iV2 on RedHat7.3

    What is causing the failure of the Oracle JDBC Development Drivers component during the Oracle9i installation, I'm getting the
    Error in writing to file classes111_g.jar
    If I skip this component then it keep on listing other files including a file.PDF file and I checked all the permissions so it is not a file permission error.
    Could someone list the steps they took to set up JAVA on their Linux box and then what you had to add exactly to your ".bash_profile"
    Perhaps this is what I'm doing wrong.
    Thnx.
    JarLoc = /tmp/OraInstall2002-10-11_11-17-22PM/temp31
    gpEntries = [[classes111_g.zip ->%ORACLE_HOME%/jdbc/lib/classes111_g.zip 1381728 plats=1=>[46] langs=1=>[en]]
    , [classes111_g.jar ->%ORACLE_HOME%/jdbc/lib/classes111_g.jar 1371600 plats=1=>[46] langs=1=>[en]]
    DllGroup = false
    Exception thrown from action: copyGroupFromJar
    Exception Name: IOException2
    Exception String: Error in writing to file /ora1/app/oracle/product/9.2.0/jdbc/lib/classes111_g.jar
    Exception Severity: 2
    Exception handling set to prompt user with options to RETRY
    User choice : Retry
    Exception thrown from action: copyGroupFromJar
    Exception Name: IOException2
    Exception String: Error in writing to file /ora1/app/oracle/product/9.2.0/jdbc/lib/classes111_g.jar
    Exception Severity: 2

    Your error has been completely addressed here http://www.puschitz.com/InstallingOracle9i.html. This is very informative. You may want to check this out before proceeding. The straight solution to this is when this error shows up, leave it open, find the native_threads/java file from the CD to the directory Oracle is asking for this. I had this problem and it turned out when I extracted and burnt it to a CD, it didn't copy the native_threads directory and others, so you want to check this as well.
    Del

  • Error writing to file during Installation

    I am installing Oracle 8.1.6 on RedHat 6.2. 80% through the installation I get the error "Error in writing to file /u01/app/oracle/product/8.1.6/lib/libagtsh.so.1.0". I skip the installation of this component and later get the message "Error in invoking target install of makefile /u01/app/oracle/product/8.1.6/otrace/lib/ins_otrace.mk".
    Any ideas what is causing these problems?

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Delaine Schneider ([email protected]):
    I am installing Oracle 8.1.6 on RedHat 6.2. 80% through the installation I get the error "Error in writing to file /u01/app/oracle/product/8.1.6/lib/libagtsh.so.1.0". I skip the installation of this component and later get the message "Error in invoking target install of makefile /u01/app/oracle/product/8.1.6/otrace/lib/ins_otrace.mk".
    Any ideas what is causing these problems?<HR></BLOCKQUOTE>
    Have you checked the obvious with the OS? Disk space, file permissions etc. because the first message may be all you need worry about.
    null

  • Error in writing to file - Oracle

    Dear All,
    We have to upgrade Oracle from 10.2.0.2 to 11.2.0.2. For this we are applying patches till 10.2.0.4. OS is AIX 6.1.
    Before proceeding I have stopped SAP, DB, Listerner and emctl also.
    But after starting the patches we found the msg that, Error in writing to file 'oracle/SID/102_64/jdk/bin/libdbgmalloc.a'.
    [/oracle/SID/102_64/jdk/jre/bin/libdbgmalloc.a(Cannot open or remove a file containing a running program.)]
    Click 'Help' for more information.
    Click 'Retry' to try again.
    Click 'Ignore' to ignore this error and go on.
    Click 'Cancel' to stop installation.
    We are in the middle of installation where deinstallation has already passed. Please help us in fixing this issue. We tried ps -ef | grep libdbgmalloc.a to check the running status but didnt find that.
    Thanks,
    Rableen

    Hi Rableen,
    You can go ahead with the solution provided above. There would be no impact on system as we have done the same on our whole landscape and did not encounter any issue after multiple round of testings.
    This happens because semaphore which uses jdk library files at OS level. You would not be able to locate any process related to that.
    Once you rename libzip.a to libzip.a_old and click on retry, another file libzip.a of newer timestamp will be put by upgrade tool.
    hostname:orasid 7> ls -rtl|grep libzip.a
    -rwxr-xr-x    1 orasid   dba          109588 20 Aug 2005  libzip.a_old
    -rwxr-xr-x    1 orasid   dba          109803 21 Apr 2008  libzip.a
    hostname:orasid 7> pwd
    /oracle/SID/102_64/jdk/jre/bin
    hostname:orasid 7>
    Nothing to worry after renaming as upgrade tool will put a new file of new date at the same place.
    Also as you are going to upgrade 11G, directory 102_64 will not be used at all after 11G upgrade. A new directory structure will be created as /oracle/SID/11202.
    Cheers !!!
    Ashish

  • Redhat 8.0 and Oracle 9i (9.2.0) Error in writing to file

    When I try to do an installation on Redhat 8.0 with Oracle 9i (9.2.0) I get the following error during the
    Installing Enterprise Manager Common
    Files 9.2.0.1.0
    Link Pending... stange.
    Error in writing to file
    /opt/oracle/product/9.2.0/jar/oem_gifs.
    jar
    I go to the directory and the file is there, around 95 megs. I have deleted it and retried, and I have tried just retrying. Nothing seems to make it go. Can anyone give me further suggestions for a fix?

    Having the same problem,except its on Redhat 8.1 beta. Installer crashes when copying README.TXT part any luck??Is it failing on the linking part of the install??

Maybe you are looking for