UTL_FILE

[i]Hi,
Is there a limitation to the size of the file that can be generated by UTL_FILE package, Or the limitation of 32k is for the buffer size? In which case, the data has to be written to the output file before the limit is reached, correct?
How to check if the buffer limit has been reached so that there is no data "loss"
Appreciate your help....
Thanks,
Oracle Fan

http://www.adp-gmbh.ch/ora/plsql/utl_file.html
Very readable documentation.

Similar Messages

  • Help needed in utl_file

    Hi,
    I have two groups in data model of my report. I am using utl_file in a formula column of report last group.it's working fine.
    but my problem is if customer has more than one invoice lines
    then all that lines not comes under only particular customer only at a time.
    For example my output is coming like this:
    Customer address: 3345 LIMITED-STUDIOS : 00033-45 PARR STREETLIVERPOOLCHESHIRE
    Invoice Lines: 0001000402106-JUL-07INV 10.47
    Customer address: 3345 LIMITED-STUDIOS : 00033-45 PARR STREETLIVERPOOLCHESHIRE
    Invoice Lines: 0001000402713-JUL-07INV 10.77
    But I am trying to get output like this:
    Customer address: 3345 LIMITED-STUDIOS : 00033-45 PARR STREETLIVERPOOLCHESHIRE
    Invoice Lines: 0001000402106-JUL-07INV 10.47
              0001000402713-JUL-07INV 10.77
    I am using fallowing code in my formula column:
    function CF_UTL_FILEFormula return Char is
    v_file_data utl_file.file_type;
    begin
    utl_file.put_line(v_file_data,:SEND_CUSTOMER_NAME:SEND_ADDRESS1:SEND_ADDRESS2:SEND_ADDRESS3:SEND_ADDRESS4:SEND_CITY:SEND_STATE:SEND_COUNTRY_DESC:SEND_POSTAL_CODE);
    utl_file.put_line(v_file_data,LN1:CF_LOCATION:C_DELIVERY_DATE:INVOICE_NUMBER:TRX_DATE:c_transaction_type:CD_TRX_AMOUNT);
    utl_file.fclose(v_file_data);
    end;
    Please help me how can I do this?

    What's the source of your Summary Column? It's not allowed to choose here the formula column in whcih you reference the summary column back. But another column should work.
    As alternativ add a formula column in the upper group with
    utl_file.put_line(v_file_data,:SEND_CUSTOMER_NAME:SEND_ADDRESS1:SEND_ADDRESS2:SEND_ADDRESS3:SEND_ADDRESS4:SEND_CITY:SEND_STATE:SEND_COUNTRY_DESC:SEND_POSTAL_CODE);
    and remove the same line out of the other formula column.

  • 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

  • (ORA-06508: PL/SQL: could not find program unit being called) utl_file

    hi all,
    I am using Oracle XE and forms 6i and am facing the above error when i try to use the utl_file utility.
    WHEN BUTTOn PRESSED
         IF (:EXPORT_IMPORT_DATA = 'E') THEN
              message(lc_status);
                             SECURITY.PKG_gen_trnsfr_data_flat_file.PROC_gen_trnsfr_data_flat_file(:DATA_FILE_PATH, :DATA_FILE_NAME, lc_status);
    PKG_GEN_TRNSFR_DATA_FLAT_FILE body
    create or replace PACKAGE BODY PKG_gen_trnsfr_data_flat_file IS
    PROCEDURE proc_gen_trnsfr_data_flat_file(p_file_location IN VARCHAR2, p_file_name IN VARCHAR2, po_status OUT VARCHAR2) IS
         lh_filename UTL_FILE.FILE_TYPE;
         ls_data VARCHAR2(2000);
         ln_count NUMBER;
         lc_error VARCHAR2(10000);
    CURSOR cur_FPM_DAMAGE_COMPENSATION IS SELECT RPAD(nvl(PDCO_CASE_CLASS,' '),1) || RPAD(nvl(PDCO_CASE_DISPOSAL_PENDING,' '),1) || RPAD(nvl(PDCO_CASE_DISPOSAL_TYPE,' '),1) || RPAD(nvl(PDCO_CC_NO,0),9) || RPAD(nvl(PDCO_CF_NO,0),9) || RPAD(nvl(PDCO_COMPEN_REALISED,0),18) || RPAD(nvl(PDCO_CONFISCATED_PRODUCE,' '),25) || RPAD(nvl(PDCO_CR_NO,0),9) || RPAD(nvl(PDCO_DAMAGE_DETAILS,' '),90) || RPAD(nvl(PDCO_DAMAGE_REPORT_NO,0),13) || RPAD(NVL(TO_CHAR(PDCO_DATE_ORDER_COMPOUNDING,'DD-MON-RRRR'),' '),15) || RPAD(NVL(TO_CHAR(PDCO_DATE_PROSECUTION,'DD-MON-RRRR'),' '),15) || RPAD(NVL(TO_CHAR(PDCO_DISPOSAL_DATE,'DD-MON-RRRR'),' '),15) || RPAD(nvl(PDCO_DR_NO,0),9) || RPAD(nvl(PDCO_FOREST_NAME,' '),50) || RPAD(NVL(TO_CHAR(PDCO_ISSUE_DATE,'DD-MON-RRRR'),' '),15) || RPAD(nvl(PDCO_LASTUPDATE_BY,' '),30) || RPAD(NVL(TO_CHAR(PDCO_LASTUPDATE_ON,'DD-MON-RRRR'),' '),15) || RPAD(nvl(PDCO_NO_OF_PERSONS_IN_THE_CASE,0),6) || RPAD(nvl(PDCO_NO_ORDER_FOR_COMPOUNDING,' '),15) || RPAD(nvl(PDCO_OFFENCE_DETAILS,' '),90) || RPAD(nvl(PDCO_OFFENCE_TYPE,' '),1) || RPAD(nvl(PDCO_OFFENDER_ADDRESS,' '),90) || RPAD(nvl(PDCO_OFFENDER_NAME,' '),200) ||
    RPAD(nvl(PDCO_OFFICIAL_NAME,' '),30) || RPAD(nvl(PDCO_RA_SIGN,' '),30) || RPAD(NVL(TO_CHAR(PDCO_RA_SIGN_DATE,'DD-MON-RRRR'),' '),15) || RPAD(NVL(TO_CHAR(PDCO_RECEIPT_DATE,'DD-MON-RRRR'),' '),15) || RPAD(nvl(PDCO_RR_NO,0),18) || RPAD(nvl(PDCO_TOOLS,0),18) || RPAD(nvl(PDCO_TOTAL,0),18) || RPAD(nvl(PDCO_VALUE_CONFISCATED_PROD,0),18) || RPAD(nvl(PDCO_VFP,0),18) || RPAD(nvl(PDCO_YDIV_DIVISION_CODE,' '),8) || RPAD(nvl(PDCO_YRAN_RANGE_CODE,' '),8) outstring FROM FPM_DAMAGE_COMPENSATION;
    CURSOR cur_FPM_DAMAGE_COMPENSATION_R IS SELECT RPAD(nvl(CIRCLE,' '),90) || RPAD(nvl(DIVISION,' '),90) || RPAD(nvl(PREV_A,0),9) || RPAD(nvl(PREV_B,0),9) || RPAD(nvl(PREV_TOTAL,0),11) || RPAD(nvl(TOT_A,0),11) || RPAD(nvl(TOT_B,0),11) || RPAD(nvl(TOT_C,0),11) || RPAD(nvl(T_A,0),9) || RPAD(nvl(T_B,0),9) || RPAD(nvl(T_C,0),9) || RPAD(nvl(X_A,0),9) || RPAD(nvl(X_B,0),9) || RPAD(nvl(X_C,0),9) || RPAD(nvl(Y_A,0),9) || RPAD(nvl(Y_B,0),9) || RPAD(nvl(Y_C,0),9) || RPAD(nvl(Z_A,0),9) || RPAD(nvl(Z_B,0),9) || RPAD(nvl(Z_C,0),9) outstring FROM fpm.FPM_DAMAGE_COMPENSATION_R;
    CURSOR cur_FPM_ENCROACHMENT IS SELECT RPAD(nvl(PENC_AREA_UNDER_ENCROACH,0),18) || RPAD(nvl(PENC_BALANCE_AREA_UN_ENC,0),18) || RPAD(nvl(PENC_ENCROACH_ID,' '),8) || RPAD(nvl(PENC_FOREST_NAME,' '),50) || RPAD(nvl(PENC_LASTUPDATE_BY,' '),30) || RPAD(NVL(TO_CHAR(PENC_LASTUPDATE_ON,'DD-MON-RRRR'),' '),15) || RPAD(nvl(PENC_LEGAL_STATUS_OF_FOREST,' '),90) || RPAD(NVL(TO_CHAR(PENC_PERIOD_FROM_UNDER_ENC,'DD-MON-RRRR'),' '),15) || RPAD(nvl(PENC_PRESENT_STATUS,' '),90) || RPAD(nvl(PENC_YDIV_DIVISION_CODE,' '),8) outstring FROM FPM_ENCROACHMENT;
    CURSOR cur_FPM_ENCROACHMENT_REMOVALS IS SELECT RPAD(nvl(PENR_ACTION_TAKEN,' '),90) || RPAD(nvl(PENR_AREA_REMOVED_ENCMNT,0),18) || RPAD(NVL(TO_CHAR(PENR_DATE,'DD-MON-RRRR'),' '),15) || RPAD(nvl(PENR_LASTUPDATE_BY,' '),30) || RPAD(NVL(TO_CHAR(PENR_LASTUPDATE_ON,'DD-MON-RRRR'),' '),15) || RPAD(nvl(PENR_PENC_ENCROACHMENT_ID,' '),8) || RPAD(nvl(PENR_PENC_YDIV_DIVISION_CODE,' '),8) outstring FROM FPM_ENCROACHMENT_REMOVALS;
    CURSOR cur_FPM_FIRE IS SELECT RPAD(nvl(PFIR_ACTION_TAKEN,' '),90) || RPAD(nvl(PFIR_AREA_EFFECTED,0),18) || RPAD(nvl(PFIR_CAUSE_OF_FIRE,' '),2) || RPAD(nvl(REPLACE(REPLACE(PFIR_DAMAGE_DETAILS,CHR(13),' '),CHR(10),' '),' '),200) || RPAD(nvl(PFIR_DAMAGE_VALUE,0),18) || RPAD(NVL(TO_CHAR(PFIR_DATE_OF_FIRE,'DD-MON-RRRR'),' '),15) || RPAD(NVL(TO_CHAR(PFIR_DATE_VISIT_DFO,'DD-MON-RRRR'),' '),15) || RPAD(NVL(TO_CHAR(PFIR_DATE_VISIT_RANGEOFFICER,'DD-MON-RRRR'),' '),15) || RPAD(nvl(PFIR_DFO_COMMENTS,' '),90) || RPAD(nvl(PFIR_DFO_SIGN,' '),30) || RPAD(NVL(TO_CHAR(PFIR_DFO_SIGN_DATE,'DD-MON-RRRR'),' '),15) || RPAD(nvl(PFIR_FIRE_NO,' '),10) || RPAD(nvl(PFIR_FOREST_NAME,' '),50) || RPAD(nvl(PFIR_LASTUPDATE_BY,' '),30) || RPAD(NVL(TO_CHAR(PFIR_LASTUPDATE_ON,'DD-MON-RRRR'),' '),15) || RPAD(nvl(PFIR_NO_OF_TREES,0),18) || RPAD(nvl(PFIR_QTY_OTH_FORST_PROD_BRNT,0),18) || RPAD(nvl(PFIR_RANGEOFFICER_COMMENTS,' '),90) || RPAD(nvl(PFIR_REPORTING_PERSON,' '),30) || RPAD(nvl(PFIR_VALUE_OTH_FORST_PROD_BRNT,0),18) || RPAD(nvl(PFIR_VALUE_TREES_BURNT,0),18) || RPAD(nvl(PFIR_VOLUME_TREES_BURNT,0),18) || RPAD(nvl(PFIR_YDIV_DIVISION_CODE,' '),8) || RPAD(nvl(PFIR_YRAN_RANGE_CODE,' '),8) outstring FROM FPM_FIRE;
    CURSOR cur_FPM_JFM_MASTER IS SELECT RPAD(nvl(PJFM_BSCM_SCHEME_CODE,' '),8) || RPAD(nvl(PJFM_JFM_ID,0),13) || RPAD(nvl(PJFM_LASTUPDATE_BY,' '),30) || RPAD(NVL(TO_CHAR(PJFM_LASTUPDATE_ON,'DD-MON-RRRR'),' '),15) || RPAD(NVL(TO_CHAR(PJFM_LAUNCH_DATE,'DD-MON-RRRR'),' '),15) || RPAD(nvl(PJFM_LOCATION,' '),20) || RPAD(nvl(PJFM_YDIV_DIVISION_CODE,' '),8) outstring FROM FPM_JFM_MASTER;
    CURSOR cur_FPM_JFM_DETAILS IS SELECT RPAD(NVL(TO_CHAR(PJFD_DATE,'DD-MON-RRRR'),' '),15) || RPAD(nvl(PJFD_EXPENDITURE,0),18) || RPAD(nvl(PJFD_LASTUPDATE_BY,' '),30) || RPAD(NVL(TO_CHAR(PJFD_LASTUPDATE_ON,'DD-MON-RRRR'),' '),15) || RPAD(nvl(PJFD_NO_OF_FPS,0),13) || RPAD(nvl(PJFD_OTHER_AREA_INCLUDED,0),18) || RPAD(nvl(PJFD_OVERALL_AREA_REGENERATED,0),18) || RPAD(nvl(PJFD_PF_AREA_INCLUDED,0),18) || RPAD(nvl(PJFD_PJFM_JFM_ID,0),13) || RPAD(nvl(PJFD_RF_AREA_INCLUDED,0),18) || RPAD(nvl(PJFD_VALUE_BENEFIT_CASH,0),18) || RPAD(nvl(PJFD_VALUE_BENEFIT_GOODS,0),18) outstring FROM FPM_JFM_DETAILS;
    CURSOR cur_FPM_PROTECTION_FIRE_MASTER IS SELECT RPAD(nvl(PPFM_AREA_ATTEM_TO_BE_PROT,0),18) || RPAD(nvl(PPFM_FINANCIAL_YEAR,' '),9) || RPAD(nvl(PPFM_LASTUPDATE_BY,' '),30) || RPAD(NVL(TO_CHAR(PPFM_LASTUPDATE_ON,'DD-MON-RRRR'),' '),15) || RPAD(nvl(PPFM_YDIV_DIVISION_CODE,' '),8) outstring FROM FPM_PROTECTION_FIRE_MASTER;
    CURSOR cur_FPM_PROTECTION_FIRE_DET IS SELECT RPAD(nvl(PPFD_AREA_ACTUALLY_PROTECTED,0),18) || RPAD(nvl(PPFD_COST,0),18) || RPAD(nvl(PPFD_FAILURE,0),18) || RPAD(nvl(PPFD_LASTUPDATE_BY,' '),30) || RPAD(NVL(TO_CHAR(PPFD_LASTUPDATE_ON,'DD-MON-RRRR'),' '),15) || RPAD(nvl(PPFD_PPFM_FINANCIAL_YEAR,' '),9) || RPAD(nvl(PPFD_PPFM_YDIV_DIVISIN_CODE,' '),8) outstring FROM FPM_PROTECTION_FIRE_DETAILS;
    BEGIN
    lc_error := 'begin';
    lc_error := p_file_location || p_file_name ;
         lh_filename := UTL_FILE.FOPEN(p_file_location, p_file_name, 'w',32767);
    lc_error := 'filename';
         SELECT COUNT(*) INTO ln_count FROM FPM_DAMAGE_COMPENSATION;
         lc_error := 'line 1';
         UTL_FILE.PUT_LINE(lh_filename, RPAD(ln_count,10) || 'FPM_DAMAGE_COMPENSATION');
         lc_error := 'line2';
         FOR i IN cur_FPM_DAMAGE_COMPENSATION LOOP
         UTL_FILE.PUT_LINE(lh_filename, i.outstring);
         END LOOP;
         SELECT COUNT(*) INTO ln_count FROM fpm.FPM_DAMAGE_COMPENSATION_R;
         UTL_FILE.PUT_LINE(lh_filename, RPAD(ln_count,10));
         FOR i IN cur_FPM_DAMAGE_COMPENSATION_R LOOP
         UTL_FILE.PUT_LINE(lh_filename, i.outstring);
         END LOOP;
         SELECT COUNT(*) INTO ln_count FROM FPM_FIRE;
         UTL_FILE.PUT_LINE(lh_filename, RPAD(ln_count,10)||'FPM_FIRE');
         FOR i IN cur_FPM_FIRE LOOP
         UTL_FILE.PUT_LINE(lh_filename, i.outstring);
         END LOOP;
         SELECT COUNT(*) INTO ln_count FROM FPM_JFM_MASTER;
         UTL_FILE.PUT_LINE(lh_filename, RPAD(ln_count,10));
         FOR i IN cur_FPM_JFM_MASTER LOOP
         UTL_FILE.PUT_LINE(lh_filename, i.outstring);
         END LOOP;
         SELECT COUNT(*) INTO ln_count FROM FPM_JFM_DETAILS;
         UTL_FILE.PUT_LINE(lh_filename, RPAD(ln_count,10));
         FOR i IN cur_FPM_JFM_DETAILS LOOP
         UTL_FILE.PUT_LINE(lh_filename, i.outstring);
         END LOOP;
         SELECT COUNT(*) INTO ln_count FROM FPM_PROTECTION_FIRE_MASTER;
         UTL_FILE.PUT_LINE(lh_filename, RPAD(ln_count,10));
         FOR i IN cur_FPM_PROTECTION_FIRE_MASTER LOOP
         UTL_FILE.PUT_LINE(lh_filename, i.outstring);
         END LOOP;
         SELECT COUNT(*) INTO ln_count FROM FPM_PROTECTION_FIRE_DETAILS;
         UTL_FILE.PUT_LINE(lh_filename, RPAD(ln_count,10));
         FOR i IN cur_FPM_PROTECTION_FIRE_DET LOOP
         UTL_FILE.PUT_LINE(lh_filename, i.outstring);
         END LOOP;
         SELECT COUNT(*) INTO ln_count FROM FPM_ENCROACHMENT;
         UTL_FILE.PUT_LINE(lh_filename, RPAD(ln_count,10));
         FOR i IN cur_FPM_ENCROACHMENT LOOP
         UTL_FILE.PUT_LINE(lh_filename, i.outstring);
         END LOOP;
         SELECT COUNT(*) INTO ln_count FROM FPM_ENCROACHMENT_REMOVALS;
         UTL_FILE.PUT_LINE(lh_filename, RPAD(ln_count,10));
         FOR i IN cur_FPM_ENCROACHMENT_REMOVALS LOOP
         UTL_FILE.PUT_LINE(lh_filename, i.outstring);
         END LOOP;
         UTL_FILE.FCLOSE_ALL;
         po_status := 'NO ERROR';      
         EXCEPTION
                   WHEN UTL_FILE.INVALID_PATH      OR UTL_FILE.INVALID_MODE THEN
                                       po_status := 'I 1';
                   WHEN UTL_FILE.INVALID_FILEHANDLE OR UTL_FILE.INVALID_OPERATION OR UTL_FILE.INTERNAL_ERROR OR UTL_FILE.WRITE_ERROR THEN
                                       po_status := 'I 2';
                   WHEN OTHERS THEN
                                       po_status := lc_error;
                                       LC_ERROR:='I 4';
                                       dbms_output.put_line(LC_ERROR);
    END;
    END;
    If i uncomment UTL_FIle.Fopen statement, the error text will be the path name and file name.
    Can anyone advise as to what should be done to resolve this on XE. It worked fine on 8i.
    I have runcatproc.sql and utlfile.sql also
    regards
    kunal

    Hi
    On 8i you would have set the UTL_DIR_PATH parameter
    in the init.ora file. Did you do this for your XE
    database? I hope you are referring to the UTL_FILE_DIR parameter. I have set this parameter to value *.
    Although the better approach would be to
    create a directory object for the file path, an
    option which was introduced in 9i..
    Can you please elaborate me on this. I tried declaring the create directory statement in the package, but that didnt help. I have already created one through sql command line. How can i use this directory as an alternative to utl_file

  • How to create/delete files from filesystem using PL/SQL ? UTL_FILE?

    Greetings,
    I will start by explaining what i intend to do.
    I have an application made in APEX. This application will have among other purposes the managment of pdf files which will reside in the filesystem.
    I have questioned the person in charge to keep the pdf files in the database and not in the filesystem but without success.
    So the pdf files reside in the filesystem and there is a record in a database table about them. A table keeps all info about the pdf, their location , size and name, creation date etc.
    The APEX application will have a mecanism to allow the deletion of the pdf files if an administrator decides.
    So it should be possible for an administrator to schedule the deletion of all pdf files whoe creation date is older than 2008 for example
    So, how can i achieve that?
    After some research i foudn about the UTL_FILE package which seems to have it takes to perform the task in issue.
    My idea was to have a script in the operating system which runs nightly and reads a file containing all file names of the pdf to be erased.
    The file which contains the names of the pdfs to be erased will be generated by the database a few minutes before.
    If there are no pds files to be erased than the file containing the names will simply be empty
    Are there any other viable solutions out there?
    And as for opening/creating the file withn the pdf names, i use:
    UTL_FILE.FOPEN (
    location IN VARCHAR2,
    filename IN VARCHAR2,
    open_mode IN VARCHAR2,
    max_linesize IN BINARY_INTEGER)
    RETURN file_type;
    And as for writing lines (a pdf name per line ), i use;
    UTL_FILE.PUT_LINE (
    file IN FILE_TYPE,
    buffer IN VARCHAR2,
    autoflush IN BOOLEAN DEFAULT FALSE);
    is there a better solution?
    thanks all.
    -> My Homepage <-
    Edited by: Igor Carrasco on Apr 14, 2009 3:11 PM
    Edited by: Igor Carrasco on Apr 14, 2009 3:12 PM

    Greetings,
    I have read that link above, some questions still though.
    I will provide some more information.
    -First the database is in a windows server.
    The windows server has a virtual drive mounted as z:\ <-- this points to a directory in virtual machine, i can manually access/create/delete files manually,i tested.
    -Second utl_file_dir is defined as * , in t that enough to cover mounted drives? ( i can't change the init.ora and reboot the db right now :( gotta wait.. )
    Do i explicitly have to define utfl_file_dir = z: ?
    -Third haven't had the chance to test it on linux or any other operating system, assuming a virtual unit is mounted successfully and that the issues above are solved i should be able to operate on any mounted drive whatever the os, right?
    Best regards

  • Problem with UTL_FILE (please see my last post on this thread)

    Hi all,
    I'm trying to get the code (procedures, functions, etc) of my schemas. I've tried it using DBMS_METADATA.GET_DDL but it fails with many objects. Finally, I'm trying to create a procedure to extract the code.
    I've created this two procedures:
    CREATE OR REPLACE PROCEDURE spool_code (code IN varchar2, propi IN varchar2) is
    CURSOR codigo is
    select text from dba_source where name = code and owner = propi order by line;
    line varchar2(4000);
    BEGIN
    open codigo;
    loop
    fetch codigo into line;
    exit when codigo%notfound;
    dbms_output.put_line(line);
    end loop
    close;
    END;
    CREATE OR REPLACE PROCEDURE ext_codigo is
    CURSOR objeto is
    select object_name, owner from dba_objects where object_type in ('PROCEDURE','FUNCTION','PACKAGE')
    and owner not in ('OUTLN','DBSNMP','SYSTEM','SYS','REPADMIN','PERFSTAT','SPOTLIGHT','MONITOR','PRUEBAS','TOAD')
    and status='VALID';
    nom varchar2(128);
    owner varchar2(30);
    BEGIN
    open objeto;
    loop
    fetch objeto into nom, owner;
    exit when objeto%notfound;
    spool_code(nom, owner);
    end loop;
    close objeto;
    END;
    And I'm calling from sqlplus to spool it:
    SQL> spool Users_code.sql
    SQL> exec ext_codigo;
    But it don't bring me results...
    where is the problem??
    Thanks in advance for your support!
    dbajug
    Edited by: dbajug on Aug 29, 2012 6:36 AM

    Hi,
    yes guys, I've set serverout on using the max limit but, always fails with:
    ERROR at line 1:
    ORA-20000: ORU-10027: buffer overflow, limit of 1000000 bytes
    ORA-06512: at "SYS.DBMS_OUTPUT", line 35
    ORA-06512: at "SYS.DBMS_OUTPUT", line 198
    ORA-06512: at "SYS.DBMS_OUTPUT", line 139
    ORA-06512: at "SYS.SPOOL_CODE", line 15
    ORA-06512: at "SYS.EXT_CODIGO", line 17
    ORA-06512: at line 1
    I'm working with a 9i version trying to extract the code to migrate it to a 11g.
    In order to avoid the buffer error, I've decide use the UTL_FILE package but I'm having another problem: my procedure now is this
    CREATE OR REPLACE PROCEDURE spool_code (code IN varchar2, propi IN varchar2) is
    CURSOR codigo is
    select text from dba_source where name = code and owner = propi order by line;
    line varchar2(4000);
    out_file UTL_FILE.File_Type;
    BEGIN
    begin
    out_file := UTL_FILE.Fopen('/export/home/oracle', 'Users_code.sql', 'w');
    exception
    when others then
    dbms_output.put_line('Error opening file');
    end;
    open codigo;
    loop
    fetch codigo into line;
    exit when codigo%notfound;
    UTL_FILE.Put_Line(out_file, line);
    end loop;
    close codigo;
    UTL_FILE.Fclose(out_file);
    END;
    The directory exists and the file too but fails with this error:
    ERROR at line 1:
    **ORA-29282: invalid file ID**
    ORA-06512: at "SYS.UTL_FILE", line 714
    ORA-06512: at "SYS.SPOOL_CODE", line 23
    ORA-06512: at "SYS.EXT_CODIGO", line 17
    ORA-06512: at line 1
    any idea? about the reason? The file is a text file on the server:
    ls -lrt /export/home/oracle/Users_code.sql
    -rw-rw-r-- 1 oracle dba 0 Aug 29 14:43 /export/home/oracle/Users_code.sql
    best regards,
    dbajug

  • Line size in UTL_FILE

    Hi,
    Can someone please tell me what is the max. number of characters that can be written using UTL_FILE in Oracle 8.1.7?

    Perhaps I should have been more specific; I wanted to know how many characters can PUT_LINE or PUT function take at one time to write. Well, in 8.1.7, it is only 1000 characters on UNIX platform. Though it is not mentioned anywhere so I am not sure if this is OS limitation. However I had to do a lot of trial and error before e finding this out. Hope this would help people on the forum.
    Thanks guys for your help. I know I can always count on you all.
    Here is the sample code. In this, although, I had defined a buffer of 4000, but it consistently gave me 'WRITE_ERROR' for PUT_LINE or PUT function, until I reduced the buffer size used with these functions to 1000. Alternatively now I will use PUT function recursively and add NEW_LINE character after the entire buffer is read.
    declare
    vstr varchar(4000);
    file_handle UTL_FILE.FILE_TYPE;
    begin
    select rpad('Testiing',990,'xyz') into vstr from dual;
    file_handle := UTL_FILE.FOPEN ('/usr/users/cornwas/workplace', 'a.txt', 'w');
    for i in 1..20 loop
    UTL_FILE.PUT_LINE(file_handle, vstr);
    UTL_FILE.FFLUSH(file_handle);
    end loop;
    UTL_FILE.FCLOSE(file_handle);
    EXCEPTION
    WHEN UTL_FILE.INVALID_PATH THEN
    RAISE_APPLICATION_ERROR(-20100,'Invalid Path');
    WHEN UTL_FILE.INVALID_MODE THEN
    RAISE_APPLICATION_ERROR(-20101,'Invalid Mode');
    WHEN UTL_FILE.INVALID_FILEHANDLE THEN
    RAISE_APPLICATION_ERROR(-20102,'Invalid Filehandle');
    WHEN UTL_FILE.INVALID_OPERATION THEN
    RAISE_APPLICATION_ERROR(-20103,'Invalid Operation -- May signal a file locked by the OS');
    WHEN UTL_FILE.READ_ERROR THEN
    RAISE_APPLICATION_ERROR(-20104,'Read Error');
    WHEN UTL_FILE.WRITE_ERROR THEN
    RAISE_APPLICATION_ERROR(-20105,'Write Error');
    WHEN UTL_FILE.INTERNAL_ERROR THEN
    RAISE_APPLICATION_ERROR(-20106,'Internal Error');
    WHEN NO_DATA_FOUND THEN
    RAISE_APPLICATION_ERROR(-20107,'No Data Found');
    WHEN VALUE_ERROR THEN
    RAISE_APPLICATION_ERROR(-20108,'Value Error');
    WHEN OTHERS THEN
    RAISE_APPLICATION_ERROR(-20109,'Unknown UTL_FILE Error');
    end;

  • Producing text file from PL/SQL procedure (UTL_FILE)?

    Hi,
    I need to produce a text file from a PL/SQL procedure. My output should be a little over 38K records and my query has 70 fields. I'd like to separate the fields by pipe delimiters in the text file. I can either concatenate all 70 fields into one variable for each record or send all 70 fields over with a pipe, whichever is easier. It looks like I can't spool within PL/SQL but UTL_FILE might be an option from what I'm reading. Does anyone have any good, simple example(s) to produce a text file using this package in calling multiple fields from a LOOP? Our os is UNIX and db is Oracle 9i.
    Also, I've read that UTL_FILE has a record output of 1,023 bytes. Is this for each record line or the whole file size? I belive the max # of characters for each line wouldn't exceed 500 characters. The 38K rows I have for the data set would be well over 1MB. If this is the case, is there a work around to produce a larger text file?
    Any suggestions and/or examples would be greatly appreciated.
    Thanks,
    Eric

    Assuming the goal is to create a text file on the database server, you can use UTL_FILE here. Each line can be 1023 characters, but you can have as many lines as you'd like.
    Tom Kyte has an example here
    http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:235814350980
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • How do I use UTL_FILE to insert a large number of fields to a file?

    Hi
    I am trying to use UTL_FILE for the first time in a Stored Procedure. I need to run a complex query to select 50 fields from various tables. I need these to be inserted into one line in the output file for all rows. Is this possible? My procedure so far is like the following
    CREATE OR REPLACE PROCEDURE PROC_TEST IS
    output_file UTL_FILE.FILE_TYPE;
    BEGIN
    FOR query in (SELECT FIELD1, FIELD2, ..........FIELD50)
    FROM TABLE A, TABLE B
    WHERE A.ID = B.ID
    ETC
    LOOP
    UTL_FILE.PUT_LINE(output_file, <put all 50 fields for all records into file> );
    END LOOP;               
    UTL_FILE.FCLOSE (output_file);
    EXCEPTION
    WHEN NO_DATA_FOUND THEN
    NULL;
    WHEN OTHERS THEN
         UTL_FILE.FCLOSE_ALL;
    RAISE;
    END PROC_TEST;
    Do I need to define 'query' (after the FOR) anywhere, also please advise with how I put all of the fields into the file.
    Thanks
    GB

    Thanks Steve,
    I have the UTL_FILE working fine now.
    I have other queries to run and conditions to apply in the same procedure, and I need to schedule via Enterprise Manager, therefore using UTL_FILE in a procedure seemed the best option. I looked up Data-pump but this seems to be an 11g feature, and we are still on 10g therefore I will not be able to use it.
    Thanks for your help.
    GB

  • How to read a specific value or a portion of text using utl_file.

    hi,
    I have a small requirement which goes as follows. I have a text file which is a resultof the sql query and it contains 16 columns as PIPE delimited text . I am using the UTL_FILE package concept to read the data. In general when we use the UTL_FILE.GET_LINE we read the entire line of text. But i need to read the 10th column of the query or the PIPE delimited text .
    Please advice.
    My query goes something like this:
    declare
    f utl_file.file_type;
    s long;
    c number := 0;
    begin
    f := utl_file.fopen('ABC_EXTRACTS','sample1.txt','R');
    loop
    utl_file.get_line(f,s);
    insert into s values (s);
    c := c + 1;
    end loop;
    exception
    when NO_DATA_FOUND then
    utl_file.fclose(f);
    dbms_output.put_line('No. of rows inserted : ' || c);
    end;

    Why don't you use varchar2 instead of long data type. I doubt you can read a portion from a file using utl_file but after doing the fetch you can do substring over the varchar2 variable and retrieve just the 10th column.
    sample sql:
    If your DB is 10g or higher, you can use the below regular expression to retrieve value based on your need.
    PRAZY@11gR1> select regexp_substr('111|222|333|444|555|666|777|888|999|000|aaa|bbb|','[^|]+',1,10) from dual;
    REG
    000
    Elapsed: 00:00:00.00Btwn, if the text file has fixed number of columns at all time, why don't you use a external table instead?
    Regards,
    Prazy
    Edited by: Prazy on Mar 22, 2010 4:11 PM

  • How to read a tab seperated data from a text file using utl_file

    Hi,
    How to read a tab seperated data from a text file using utl_file...
    I know if we use UTL_FILE.get_line we can read the whole line...but i need to read the tab separated value separately.....
    Thanks in advance...
    Naveen

    Naveen Nishad wrote:
    How to read a tab seperated data from a text file using utl_file...
    I know if we use UTL_FILE.get_line we can read the whole line...but i need to read the tab separated value separately.....If it's a text file then UTL_FILE will only allow you to read it a line at a time. It is then up to you to split that string up (search for split string on this forum for methods) into it's individual components.
    If the text file contains a standard structure on each line, i.e. it is a fixed delimited structure, then you could use external tables to read the data instead.

  • Error writing data in a flat file using UTL_FILE feature

    Hi All,
    I have written a package which fetches data from four different cursors and inserts into a temporary table.
    Now this temporary table is used to write data in a file using the UTL_FILE feature.
    fhandler :=
    UTL_FILE.fopen (l_path,'Demand_Transactions_'
    || TO_CHAR (SYSDATE, 'YYYYMMDDHH24MI')
    || '.txt',
    'w',
    max_linesize => 32767
    This table has 62593 records and when it starts writing data into the file from the table it errors out after writing 30045 records with the error - ORA-01722: invalid number.
    Can anyome please advise me is it because of the max_linesize => 32767. If not then what can be the possible reason.
    Any help in this would be highly appreciated.
    Regards,
    Shruti

    891330 wrote:
    Hi All,
    I have written a package which fetches data from four different cursors and inserts into a temporary table.
    Now this temporary table is used to write data in a file using the UTL_FILE feature.
    fhandler :=
    UTL_FILE.fopen (l_path,'Demand_Transactions_'
    || TO_CHAR (SYSDATE, 'YYYYMMDDHH24MI')
    || '.txt',
    'w',
    max_linesize => 32767
    This table has 62593 records and when it starts writing data into the file from the table it errors out after writing 30045 records with the error - ORA-01722: invalid number.
    Can anyome please advise me is it because of the max_linesize => 32767. If not then what can be the possible reason.Max linesize is the number of characters in a line before a newline has to be issued, not the number of rows written.
    The error would indicate that you have a character to number conversion going on somewhere but the characters are not numeric so it's failing that conversion.
    This doesn't sound like a UTL_FILE issue, but more to do with how you are building up your strings to output to the file.
    You would need to show us your code that builds up the lines you are writing out, with details of the datatypes of any of the columns/variables included in that.

  • HOW TO READ DATA FROM A FILE AND INSERT INTO A TABLE USING UTL_FILE

    Hi..
    I have a file.I want to read the data from file and load it into a table using utl_file.
    how can I do it?
    Any reply apreciated...

    Hi,
    This is not your requirment but u can try this :
    CREATE OR REPLACE DIRECTORY text_file AS 'D:\TEXT_FILE\';
    GRANT READ ON DIRECTORY text_file TO fah;
    GRANT WRITE ON DIRECTORY text_file TO fah;
    DROP TABLE load_a;
    CREATE TABLE load_a
    (a1 varchar2(20),
    a2 varchar2(200))
    ORGANIZATION EXTERNAL
    (TYPE ORACLE_LOADER
    DEFAULT DIRECTORY text_file
    ACCESS PARAMETERS
    (FIELDS TERMINATED BY ','
    LOCATION ('data.txt')
    select * from load_a;
    CREATE TABLE A AS select * from load_a;
    SELECT * FROM A
    Regards
    Faheem Latif

  • Error while using UTL_FILE

    I am getting the following error while using UTL_FILE procedure while using UTL_FILE.FOPEN procedure
    from system account. I am using Windows XP with NTFS.
    SQL> create or replace directory FILE_DIR as 'C:\'
    2 /
    Directory created.
    SQL> grant read on directory FILE_DIR to public;
    Grant succeeded.
    1 create or replace PROCEDURE file_upload IS
    2 v_file_name VARCHAR2(200);
    3 v_file_type UTL_FILE.FILE_TYPE;
    4 v_line VARCHAR2(1000);
    5 BEGIN
    6 v_file_name := 'customers_'||TO_CHAR(SYSDATE,'dd')||TO_CHAR(SYSDATE,'MON')||TO_CHAR(SYSDATE,'YYYY')||'.txt';
    7 v_file_type := UTL_FILE.FOPEN('FILE_DIR','V_FILE_NAME','r',1000);
    8 UTL_FILE.GET_LINE(v_file_type,V_LINE,1000);
    9 UTL_FILE.FCLOSE(v_file_type);
    10 DBMS_OUTPUT.PUT_LINE(V_LINE);
    11* END;
    SQL> exec file_upload;
    BEGIN file_upload; END;
    ERROR at line 1:
    ORA-29283: invalid file operation
    ORA-06512: at "SYS.UTL_FILE", line 475
    ORA-29283: invalid file operation
    ORA-06512: at "SYSTEM.FILE_UPLOAD", line 7
    ORA-06512: at line 1
    I appreciate if someone can help me in this regard.
    Thanks in Advance.
    Regards
    Muhammad ALi

    Hello,
    What exactly are you trying to do? Here I got 2 examples for you , replace with your directory name and pick right option for 'a' (append) or 'w' (write) or 'R' (read).
    To read from a directory_ . This will read an existing file 'customer.txt" from the directory
    {code}
    CREATE OR REPLACE PROCEDURE .file_upload
    IS
    v_file_name VARCHAR2 (200);
    v_file_type UTL_FILE.file_type;
    v_line VARCHAR2 (1000);
    BEGIN
    v_file_name := 'customers.txt';
    v_file_type := UTL_FILE.fopen ('EXT_TABLES', v_file_name, 'R');
    UTL_FILE.get_line (v_file_type, v_line); -- Error was here
    DBMS_OUTPUT.put_line (v_line);
    UTL_FILE.fclose (v_file_type);
    END;
    {code}
    _*To open a file*_ This will create customer_XXXXX file under the directory
    {code}
    CREATE OR REPLACE PROCEDURE testme.file_upload
    IS
    v_file_name VARCHAR2 (200);
    v_file_type UTL_FILE.file_type;
    v_line VARCHAR2 (1000);
    BEGIN
    v_file_name := 'customers_'
    || TO_CHAR (SYSDATE, 'dd')
    || TO_CHAR (SYSDATE, 'MON')
    || TO_CHAR (SYSDATE, 'YYYY')
    || '.txt';
    v_file_type := UTL_FILE.fopen ('EXT_TABLES', v_file_name, 'a');
    UTL_FILE.put_line (v_file_type, v_line);
    DBMS_OUTPUT.put_line (v_line);
    UTL_FILE.fclose (v_file_type);
    END;
    {code}
    Regards
    Edited by: OrionNet on Jan 29, 2009 12:30 AM

  • Issue while accessing a file using UTL_FILE

    Hi,
    My requirement is to check for the existence of a file in the file system(apps tier) and then launch a conc program to load the data.
    There is a separate DB tier.
    I am trying to use UTL_FILE.fopen to indirectly see if the file exists
    and then proceed and I am trying to use UTL_FILE.fopen for that.
    The file is placed in the apps tier. I have created a directory in the database with the path and using that in the UTL_FILE.FOPEN call.
    However I am getting the following error. ORA-29283 - An attempt was made to read from a file or directory that does not exist, or file or directory access was denied by the operating system.
    What could be the issue here? Is there anything that I need to do after creating the directory?.
    Thanks,
    Balaji

    /Pl post details of OS, database and EBS versions.
    Are the Apps and DB servers physically separate ? If so, the directory on the Apps server where the file resides will have to be visible/updateable to the DB server in order for UTL_FILE to be able to read/write to it.
    HTH
    Srini/
    The apps and db servers are separate. EBS version is 11.5.10.2 and the OS is unix.
    How do I make the directory in apps server visible/updateable to the DB server?. I have created a directory in the database with the location of the file in apps tier.
    Thanks for your quick reply
    Regards
    Balaji

  • ORA-03123 while using UTL_FILE package in oracle forms 10g

    hi all,
    i have created a directory 'REPORTS' as 'E:\EXCEL_TESTING_FORM\' and give grant read,write this directory to scott.
    and also given grant execute on UTL_FILE to scott;
    i have written this code in a button-pressed trigger and my file name is somename.xls file
    After printing the first line like 7369SMITH3000 in a single cell when it is going to print the second employee record it is showing
    ORA-03123 inside the loop.
    CURSOR EMP_DATA IS
         SELECT * FROM SCOTT.EMP;
    C_REF EMP_DATA%ROWTYPE;
    L_FILE UTL_FILE.FILE_TYPE;
    V_PATH VARCHAR2(200) := '';
    BEGIN
         V_PATH := 'REPORTS';
    L_FILE := UTL_FILE.FOPEN (V_PATH,P_FILE_NAME, 'W');
    OPEN EMP_DATA;
    LOOP
         FETCH EMP_DATA INTO C_REF;
         EXIT WHEN EMP_DATA%NOTFOUND;
              UTL_FILE.PUT_LINE(L_FILE, TO_CHAR(C_REF.EMPNO));
              UTL_FILE.PUT_LINE(L_FILE, C_REF.ENAME);
              UTL_FILE.PUT_LINE(L_FILE, TO_CHAR(C_REF.SAL));
    END LOOP;
    CLOSE EMP_DATA;
    UTL_FILE.FFLUSH(L_FILE);
    UTL_FILE.FCLOSE(L_FILE);
    please guide me how to avoid that error and also how to print cell wise why because it is print in a single cell.
    please reply...

    hi Andreas Weiden,
    No it is not a network-drive. i have total 0f 3 drives
    one is of c drive for wind sp2 and in d i have loaded oracle database and i have created a directory on e drive i.e 'E:\EXCEL_TESTING_FORM\'
    in that i have created a excel file i.e called taru.xls.
    so i want to know where is the problem.
    please reply...

Maybe you are looking for

  • Calling a method that returns values in a map - using JSTL

    Hi I have a method within an object that returns a List for a particular category public List<String> getFieldsInCategory(String categoryName){     return _categoryFieldsMap.get(categoryName); //This is a map that returns a list                      

  • Problem with document splitting

    Hi, I am encountering a problem with document splitting, where in while doing clearing of down payment against miro invoice profit center of first line item is over ridding profit center of second line item (line items are two different materials in

  • AWT components in swing not working

    Hi, We are developing a swing based GUI application. Here we add a third party AWT based component into the JPanel. But if we add that AWT component, it does not show our JMenuItems properly. Can somebody tell me what is the problem with the code bel

  • How much performance is impacted if the Stored outline is used globally?

    Hi, One of the queries that we are having problem with and we are trying to use the Stored outline so that we freeze the execution plan. The vendor is telling us that it should set globally (ALTER SYSTEM not SESSION) , but we disagreed because this w

  • Regenrate STACK XML  for EHP5

    Hello Guys! I have issue here, there is difference file loaded while i regenrate the XML with addtional technical usage. How will i knows which files are added today while i regenrate the XML, so that i can download those files instead of downloading