Export CLOB field (long= 4202083) to a file with UTL_FILE.PUT or PUT_LINE

Hello,
I'm trying to export a CLOB field to a txt file. It's a xml string in the CLOB. I have used different methods but the only which i can use is PUT, PUT_LINE.
But:
- PUT does only export the 32565 characters. I see that the output of l_pos is 4202084 but these are not exported. I have tried FFLUSH, but this gives a error or my syntax is not correct.
- PUT_LINE is exporting the complete CLOB, but after every 32656 is new line is added and if I want to look with altove then I have to remove 129 times the new line. Thats not the way I want to go.
Is it an idea, if it is possible, that I write 32565 chars to the buffer (file), read these 32565 from the buffer minus one (=without \r\n), delete the last 32565 chars from buffer and append/put the chars 32565 minus the \r\n to the buffer again. I hope there will be a better idea but....
Has anybody an idea how I can solve this? Or what do I wrong?
Any help would be appreciated.
Beneath my code.
Nico
CREATE OR REPLACE DIRECTORY documents AS 'D:\TEST';
SET SERVEROUTPUT ON
DECLARE
  l_file    UTL_FILE.FILE_TYPE;
  l_clob    CLOB;
  l_buffer  VARCHAR2(32767);
  l_amount  BINARY_INTEGER := 32565;
  l_pos     INTEGER := 1;
  l_lengte  number;
  l_lineCount number := 0;
BEGIN
  SELECT PAYLOAD
  INTO   l_clob
  FROM   icepayloadext ext
  WHERE  EXT.PAYLOADTYPE in ('POST')
    AND  substr(payload, 0, 2000) like '%181015%'
    AND  ext.LSTIME between to_date('10-10-2012 00:00:00', 'dd-mm-rrrr HH24:mi:ss') and to_date('10-10-2012 17:30:00', 'dd-mm-rrrr HH24:mi:ss');
  l_lengte := DBMS_LOB.GETLENGTH (l_clob);
  DBMS_OUTPUT.PUT_LINE('lengte clob veld: ' || l_lengte);
  l_file := UTL_FILE.fopen('DOCUMENTS', 'Sample1.txt', 'w', 32767);
  LOOP
    DBMS_LOB.read (l_clob, l_amount, l_pos, l_buffer);
    UTL_FILE.PUT(l_file, l_buffer);
    UTL_FILE.FFLUSH (l_file);
    --UTL_FILE.PUT_LINE(l_file,'alles geschreven');
    l_pos := l_pos + l_amount;
    DBMS_OUTPUT.PUT_LINE('Offset position: ' || l_pos);
    if (l_pos > l_lengte) then
        exit;
    end if;
  END LOOP;
  UTL_FILE.fclose(l_file);
--EXCEPTION
  --WHEN OTHERS THEN
  --  DBMS_OUTPUT.put_line(SQLERRM);
    --UTL_FILE.fclose(l_file);
END;
/

You can always try it the binary way:
DECLARE
  l_file UTL_FILE.FILE_TYPE;
  l_clob CLOB;
  l_buffer VARCHAR2(32767);
  l_amount BINARY_INTEGER := 32565;
  l_pos INTEGER := 1;
  l_lengte number;
  l_lineCount number := 0;
BEGIN
  l_clob := rpad( to_clob( 'test' ), 60000, 'test' );
  l_lengte := DBMS_LOB.GETLENGTH (l_clob);
DBMS_OUTPUT.PUT_LINE('lengte clob veld: ' || l_lengte);
  l_file := UTL_FILE.fopen( 'MY_DIR', 'Sample1.txt', 'wb', 32767 );
  LOOP
    begin
      DBMS_LOB.read (l_clob, l_amount, l_pos, l_buffer);
    exception
      when no_data_found then exit;
    end;
--    UTL_FILE.PUT_RAW( l_file, utl_raw.cast_to_raw( l_buffer ) ); -- file in database character set
    UTL_FILE.PUT_RAW( l_file, utl_i18n.string_to_raw( l_buffer, 'WE8MSWIN1252' ) );
    l_pos := l_pos + l_amount;
DBMS_OUTPUT.PUT_LINE('Offset position: ' || l_pos);
  END LOOP;
  UTL_FILE.fclose(l_file);
END;Anton

Similar Messages

  • Extracting clob/blob/long datatypes in delimited file

    I have a few tables in database that have clob/blob/long datatypes. I need to unload this data into delimited file and reload the data into another database. I don't want to use export/import.
    Currently the code that i have can handle varchar2, number, date datatypes quite easily using sqlloader.
    The tables are not too big (hundred to 10k rows approximately) and performance is important but not crucial. The script can run for a few minutes unloading data, that is fine. Code maintenance is of higher priority with pl/sql being the preferred scripting language.
    From the sqlloader manual, i glean that use of special delimiter is important, something like <startlob> and <endlob> .
    I need ideas on how to do this.

    Hi Buddy.
    I am having same kind of Problem. I am using very similar procedure Instead of PUT_RAW I am using put line.
    Writing is not a problem after writing the image into a file I cannot open that. That means Image got corrupted. If you find out some solutions for your problem please help me
    My email id is [email protected]
    Thanks
    AJI

  • Exporting Long Projects to AAC Files with Chapters

    Hey
    Is it possible to export an AAC file with chapters at around two hours in length?
    I get the "maximum file size of 2gb exceeded" if I try from Garage band (even though the wav the project is made from is made from is only 1.2Gb and the estimated AAC file after export is 58mb)
    I've also tried from the latest version of Sound Track Pro, but that just hangs on export.
    Anyone have any clues?
    All the best,
    Gus

    I don't think you there is a command to do what you are asking automatically for a bunch of clips, but FCP X supports chapter markers. You just have to add them in the timeline.
    If the project settings equal the clip settings and the export settings, there should be no transcoding involved.
    However, I believe that a simpler solution can be achieved (and this one is guaranteed to do no transcoding).
    Download and install QTCoffee (a free download from http://www.3am.pair.com/QTCoffee.html)
    Open a terminal window, type "catmovie -o mymovie.mov -auto-chapters "
    (without the quotes but with the trailing SPACE; use the name you want to give the new movie instead of mymovie.mov)
    Drag the movie files into the terminal window. Press ENTER.
    Boom! (couldn't resist :-))
    p.S.: By default this will place the newly created movie in your home folder (or on whatever is the active directory in the terminal shell at the time)

  • How to export XY graph picture to clipboard (or file) with labview 6i

    Hello,
    I would like to export XY graph picture to clipboard (or file) to insert it in a word document using labview 6i
    I found example for labview 8 using invokenode but not with labview 6i
    But this invokenode doesn't exist in labview 6i : here's what I found in labview 6i
     Does anyone knows how to use this one ?
    thanks in advance
    Solved!
    Go to Solution.

    I would recommend you use Write PNG File.vi instead of Write JPG File.vi unless the place you are using it cannot handle PNGs.  The PNG will be much better quality and should be about the same size for this type of image.
    Message Edited by DFGray on 02-03-2010 07:22 AM
    This account is no longer active. Contact ShadesOfGray for current posts and information.

  • How to export "gif" animation frames as individual .psd files with layers intact?

    Hi, after creating an extended 25 frame animation (as if building a .gif) I would like to export each frame to individual .psd files with all the layers showing in each respective frame intact as separate editable layers (rather than each frame as a flattened one layer image/psd)...how can this be done? thanks

    maybe it would be easiest if there were just a script which would delete all the layers not visible in a frame but leave the visible layers unflattened, then the file could be saved with a new_name_001 etc., then the deletions could be undone manually via option+command z, the animation advanced by a frame...repeat
    is there a script which deletes all but the visible layers in a frame -- but leaves those which are visible unflattened/editable?
    thanks

  • Can no longer edit app descriptor file with 3.4 - really?

    Until now, when publishing to AIR from Flash Professional, I could manually edit the app descriptor XML with a little workaround:
    1. Set up my publish settings in Flash Professional and click OK
    2. Then edit the XML file and save it
    3. Then Publish from Flash Professional WITHOUT opening the Publish Settings again (which would recreate the XML file).
    This has been CRUCIAL to me in order to add certain elements to the XML file such as <extensions> I want to include with my project.
    However, this seems impossible to do with the 3.4 AIR SDK release version. When I try, it ignores my manual edits of the XML file and simply removes them when I publish. This is a HUGE problem because now I can no longer add <extensions> in the app descriptor file (and this can't be done from the Flash Professional GUI).
    Anyone have ANY idea how to keep adding my extensions to the app descriptor file?

    Hello,
    I have the same problem, but not the same solution : I have an old air application under Air 2.0, with an automatic updater, and wanted to make an intermediate application as seen here : http://helpx.adobe.com/air/kb/update-air-2-or-earlier.html .
    So I have to change the application descriptor by hand. But Flash CS6 always overwrite this descriptor with its own datas while exporting.
    How can I change my application descriptor for this intermediate version ? I have Flash CS5, but not Flash CS5.5, and the extension for Flash CS5 doesn't exist anymore !
    Thanks !

  • How to export diadem channels to an existing excel file with a certain configuration

    Hello,
    I would like to export some channels from the Data Portal of Diadem  to an existing excel file. The excel file consists of many spreadsheets and each channel  should match one spreadsheet.
    I´ve tried to use EXCELExport() function but it doesn´t work.(this function is designed for something else, it generates a new excel file). I´ve tried to access to each spreadsheet and copy the information throughout a for statement but this solution needs a lot of time. If somebody has any idea, please help.   
    Solved!
    Go to Solution.

    Hi Ovidius,
    You have two options that I can think of.  You can export the data from the Data Portal to a temporary file, probably a CSV file, then load the data from file into the Excel template, OR you could stick with the Excel ActiveX approach but change to assigning a range of cells instead of individual cell values one at a time.
    There is an Excel File Export option in DIAdem, but it always creates a new Excel file, it can not be used to export to an existing Excel file.
    Brad Turpin
    DIAdem Product Support Engineer
    National Instruments

  • Dbms_lob.fileopen gives ORA-22288. Can open the same file with utl_file.

    What could cause the following behaviour:
    Database 11gR2
    declare
       l_amt        number := dbms_lob.lobmaxsize;
       l_dst_loc    clob;
       l_dst_offset number := 1;
       l_lang_ctx   number := dbms_lob.default_lang_ctx;
       l_src_loc    bfile;
       l_src_offset number := 1;
       l_warning    number;
    begin
       l_src_loc := bfilename('ODS_SERVER_DIRECTORY', '_CIVKD_ASU.CSV');
       dbms_lob.createtemporary(l_dst_loc, true);
       dbms_lob.fileopen(l_src_loc, dbms_lob.file_readonly);
       dbms_lob.loadclobfromfile(l_dst_loc
                                ,l_src_loc
                                ,l_amt
                                ,l_dst_offset
                                ,l_src_offset
                                ,dbms_lob.default_csid
                                ,l_lang_ctx
                                ,l_warning);
       commit;
       dbms_lob.fileclose(l_src_loc);
       dbms_output.put_line(substr(l_dst_loc, 1, 200));
    end;
    ORA-22288: file or LOB operation FILEOPEN failed
    ORA-06512: in "SYS.DBMS_LOB", line 805
    ORA-06512: in line 31
    22288. 00000 -  "file or LOB operation %s failed\n%s"
    *Cause:    The operation attempted on the file or LOB failed.
    *Action:   See the next error message in the error stack for more detailed
               information.  Also, verify that the file or LOB exists and that
               the necessary privileges are set for the specified operation. If
               the error still persists, report the error to the DBA.However opening and reading the exact same file succeeds when using utl_file.
    declare
       l_file utl_file.file_type;
       l_regel varchar2(4000);
    begin
       l_file := utl_file.fopen('ODS_SERVER_DIRECTORY', '_CIVKD_ASU.CSV', 'R');
       -- Haal de volgende regel op
       utl_file.get_line(l_file, l_regel);
       dbms_output.put_line(l_regel);
       utl_file.fclose_all;
    end;So it seems the file is available and accessable by the database.
    It's the first time we run into this particular error and it's one of the first 11gR2 instances so maybe there is something 11g specific we don't know about?

    Some progress made. It turns out the directory object points to a shared drive. It's a windows server and Oracle runs as Local System. I always thought that it was impossible to read anything from a shared drive in this situation. Apparently in some situations you can using utl_file but not usign dbms_lob.

  • EA 2.1. Can't export CLOB columns.

    Hello:
    I don't know the reason why CLOB column export is not available or incorrect...
    In EA 2.1. version SQL developer "truncates" the CLOB field longer than 4000 characters..
    Why?
    *I can do that succesfully with TOAD.....*

    Because it's a missing feature.
    Any enhancement requests should go to the SQL Developer Exchange, so others can vote and add weight for possible future implementation.
    Regards,
    K.

  • Export result of an execute_query to a file ( txt , EXCEL , etc..)

    i work with Forms6i, and i want to export the result of an execute_query to file with any extention.
    the execute_query is applicated to a block after pressing button Execute.
    thanks in advance

    Hi,
    check out TEXT_IO package on Forms' Help...it should be what you are looking for.
    Bye, Marco

  • Is it possible to export a DVDSP menu as .PSD Photoshop file?

    I promise this will be the last question for tonight. Is it possible to export a DVDSP menu as .PSD Photoshop file with its layers intact? I'd like to examine the structure to see if there's an easy way to re-create all my EncoreDVD menus as DVDSP menus.
    Peace, BJ

    Without opening DVDSP, I can't say for sure, but is there an option to export the menu as Movie to Image Sequence? Is there an option to export the menu at all? Sorry for asking a question to answer a question, but I don't have my scratch disk with me and don't want to open DVDSP without having my current project with me. However, the image sequence wouldn't give you layers. Simply put, I don't think so. Apple's apps have played well when it comes to importing .psd files, but as far as creating them, not so well. As far as recreating Encore Menus, is there an XML type file that's compatible with both Encore and DVDSP where you could just reconnect your media assets in DVDSP and then import this XML file?
    Good luck either way and report back with what you find,
    -Brian

  • How to create flat file with fixed lenght records

    I need help to export an Oracle table to a flat file with fixed lenght and without columns separator.
    the fixed length is the more important demand.
    My table have 50 columns with varchar, date and number .
    Date and number columns may be empty, null o with values.
    Thanks a lot for any help.
    [email protected]

    Hi,
    You can use this trick:
    SQL>desc t
    Name                                      Null?    Type
    NAME                                               VARCHAR2(20)
    SEX                                                VARCHAR2(1)
    SQL>SELECT LENGTH(LPAD(NAME,20,' ')||LPAD(SEX,1,' ')), LPAD(NAME,20,' ')||LPAD(SEX,1,' ') FROM T;
    LENGTH(LPAD(NAME,20,'')||LPAD(SEX,1,'')) LPAD(NAME,20,'')||LPA
                                          21                    aF
                                          21                    BM
                                          21                    CF
                                          21                    DM
    4 rows selected.
    SQL>SELECT *  FROM t;
    NAME                 S
    a                    F
    B                    M
    C                    F
    D                    M
    4 rows selected.Regards

  • Can not rename created file via UTL_FILE package

    Hi,
    I am wondering why I am not able to rename file after the procedure has created it?
    I am closing the file with UTL_FILE.FCLOSE (v_file);
    but it seems that oracle still keep it open.
    Any suggestions?
    Thanks
    BEGIN
    SELECT TO_CHAR (SYSDATE, 'YYYYMMDD')
    INTO v_sysdate4filename
    FROM DUAL;
    v_filename :=
    ('MyFileName_' || v_sysdate4filename || '.txt'
    v_file := UTL_FILE.FOPEN ('MY_DIR', v_filename, 'w');
    FOR v_current_row IN my_c
    LOOP
    UTL_FILE.PUT_LINE (v_file,
    v_current_row.record_type
    || v_current_row.operation_type
    || v_current_row.child_id
    || v_current_row.parent_id
    || v_current_row.start_date
    || v_current_row.end_date
    || v_current_row.process_field
    END LOOP;
    UTL_FILE.FCLOSE (v_file);
    END ;

    (I have administrator rights) Again, If you are not able to rename the file, what the error message is returned by the OS.
    Did you try to disconnect your Oracle session and then try?

  • FILE SIZE LIMIT WITH UTL_FILE?

    Hello all,
    is there any file size limit using utl_file on SUSE LINUX 5.3
    (RDBMS 8.0.5)?
    We have created a file with UTL_FILE.FOPEN, put some line into it
    (UTL_FILE.PUT_LINE), and close the file (UTL_FILE.FCLOSE).
    The file size is never greater than 32 kB.
    On 7.3.4 the same procedure works fine with files larger than 1
    MB.
    Thx
    R. Petuker
    null

    Robert Petuker (guest) wrote:
    : Hello all,
    : is there any file size limit using utl_file on SUSE LINUX 5.3
    : (RDBMS 8.0.5)?
    : We have created a file with UTL_FILE.FOPEN, put some line into
    it
    : (UTL_FILE.PUT_LINE), and close the file (UTL_FILE.FCLOSE).
    : The file size is never greater than 32 kB.
    : On 7.3.4 the same procedure works fine with files larger than 1
    : MB.
    : Thx
    : R. Petuker
    Robert,
    There is no limit on the size of the file created using the
    utl_file package. It could be the limitation of the shell
    above which you are working on. You may verify the filesize
    limit of the shell and try it again.
    Maturi
    null

  • Export XML data from a CLOB field using sql developer

    I have a table that contains a CLOB field, each record is a complete XML in itself. After running the select query i am exporting this data by right clicking on the answer set, while the export completes the data for each record gets truncated.
    When i chose to save the export in loader format i get the complete records but now there are n files created for n records exported.
    Is there a way i can get alll the records in a single file wirthout any truncation.
    Thanks in advance!

    You might try delimited format or csv, with no enclosures if desired.

Maybe you are looking for