Write a CLOB on a file

Hello

I need to create a package that should generate output in an XML file.

Between the different file tag, there is a ImageData, which must contain a Base64 attachment. The attachment is stored in a CLOB, and thanks to the ENCODEBLOB function (below is the code for example), it converts the Base64 attachment and store it in a CLOB.

The CLOB consists of text lines of 64 characters.

I need to write them in the XML file into 32676 character lines. In the example below, the file prints as lines of 64 characters.

This is my plan:

CREATE OR REPLACE PACKAGE BODY MYPACKAGE

IS

(PROCEDURE) ADD

o_x_err in out varchar2

)

IS id_file utl_file.file_type;

v_allegato BLOB;

v_directory varchar2 (200): = "TEST_EXT";

v_file_name varchar2 (200);

v_clob CLOB.

compensate for number: = 1;

number amount: = 32767;

number Len: = dbms_lob.getlength (v_clob);

lc_buffer varchar2 (32767).

/ * CODE... * /.

Id_File: = Utl_File.Fopen (v_Directory, v_File_Name, 'w', 32767);

/ * CODE... * /.

UTL_FILE. Put_line (ID_FILE, '< reg: ImageData >');

----------------------------------------------------------------------------

ENCODEBLOB (v_allegato, v_clob);  -FUNCTION CODE IS UNDER THIS CODE

offset: = 1;

amount: = 32767;

Len: = dbms_lob.getlength (v_allegato);

Start

If (dbms_lob.isopen (v_allegato)! = 1) then

DBMS_LOB. Open (v_allegato, 0);

end if;

amount: = 2000;

While (offset, len)

loop

DBMS_LOB. Read (v_allegato, amount, offset, lc_buffer);

UTL_FILE.put_line (id_file, codification (lc_buffer), false);

offset: = offset + amount;

end loop;

If (dbms_lob.isopen (v_allegato) = 1) then

DBMS_LOB. Close (v_allegato);

end if;

exception

while others then

dbms_output.put_line (' error: ' |) SQLERRM);

end;

/ * CODE... * /.

UTL_FILE. FCLOSE (id_file);

/ * CONTINUE * /.

WRITING OF THE END;

procedure EncodeBlob (blobSource in clobBase64 in a clob, blob) is

constant number of step: = 3 * 1024;

Start

I'm in 0.trunc ((DBMS_LOB. GetLength (blobSource) - 1) / step) loop

clobBase64: = clobBase64 |

UTL_RAW.cast_to_varchar2)

() UTL_ENCODE.base64_encode

DBMS_LOB. SubStr (blobSource, step, i * step + 1)

)

);

end loop;

end encodeblob;

END MYPACKAGE;

/

It is a part of the content of the BLOB:

%PDF-1.3

3 0 obj

< <

/ Type /XObject

/ / Image subtype

/ Filter /DCTDecode

/Width 1606

/Height 2277

Wake up 274917

/ BitsPerComponent 8

/ Space colorimetric /DeviceRGB

> >

data flow

Ÿoÿa JFIF È È ÿþ LEAD Technologies Inc. V1.01 Ÿu «...»

And this part of the content of CLOB after ENCODEBLOB:

JVBERi0xLjMNCjMgMCBvYmoNCjw8DQogIC9UeXBlIC9YT2JqZWN0DQogIC9TdWJ0

eXBlIC9JbWFnZQ0KICAvRmlsdGVyIC9EQ1REZWNvZGUNCiAgL1dpZHRoIDE2MDYN

CiAgL0hlaWdodCAyMjc3DQogIC9MZW5ndGggMjc0OTE3DQogIC9CaXRzUGVyQ29t

cG9uZW50IDgNCiAgL0NvbG9yU3BhY2UgL0RldmljZVJHQg0KPj4NCnN0cmVhbQ0K

/9J/4AAQSkZJRgABAAEAyADIAAD / / gAfTEVBRCBUZWNobm9sb2dpZXMgSW5jLiBW

MS4wMQD/2wCEAAYGBgkGCQ8JCQ8PCgoKDxAODg4OEBAQEBAQEBAQEBAQEBAQEBAQ

EBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBABBgkJDAkMDgkJDhAODA4QEBAQEBAQ

EBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEP/EAaIA

AAEFAQEBAQEBAAAAAAAAAAABAgMEBQYHCAkKCwEAAwEBAQEBAQEBAQAAAAAAAAEC

AwQFBgcICQoLEAACAQMDAgQDBQUEBAAAAX0BAgMABBEFEiExQQYTUWEHInEUMoGR...

Finally, it is a part of the output file:

... < reg: ImageData >

JVBERi0xLjMNCjMgMCBvYmoNCjw8DQogIC9UeXBlIC9YT2JqZWN0DQogIC9TdWJ0

eXBlIC9JbWFnZQ0KICAvRmlsdGVyIC9EQ1REZWNvZGUNCiAgL1dpZHRoIDE2MDYN

CiAgL0hlaWdodCAyMjc3DQogIC9MZW5ndGggMjc0OTE3DQogIC9CaXRzUGVyQ29t

............... < / reg: ImageData >...

Can someone help me?

DBMS_XSLPROCESSOR.clob2file () wrote the clob in a separate file, I need that must be part of a more complex file.

It seems that you generate the XML code by pieces by issuing fragment one by one, using UTL_FILE.

I have to say that this is not a good approach: code useless complex, maintenance more difficult, more likely to generate content that is not valid.

I suggest that you build the entire XML document first, in an XMLType variable, using preferably SQL/XML (guaranteeing a well-trained content).

Then use DBMS_XSLPROCESSOR at the end, so that you don't need to worry about stuff UTL_FILE this annoying.

If it is possible to have longer lines of 32 K bytes is preferable.

Yes of course.

Use the REPLACE() function to remove the product in all LF base64 CLOB.

Tags: Database

Similar Questions

  • Write a CLOB variable in a file in the log file

    Hi, I am currently building a dynamic sql statement in a plsql procedure that stores the instruction in a CLOB variable (the statement is very long), which has been declared as:

    vc_sql_statement CLOB.
    Now, I want to write this statement to a file using the UTL FILE function.

    Because the variable is greater than 32K, can anyone please suggest another way of how I can file this statement in a log file.

    I use version oracle 11g.

    Thank you very much.

    Three ways to do it.

    http://www.morganslibrary.org/howcani.html

    Look at #4 on the page linked above.

  • write a CLOB data type to a file.

    Hi all

    I use Oracle 10 g

    I want to write a CLOB in an external file on the DB server. I used the below:



    F: = UTL_FILE. FOPEN (FILE_NAME, 'FILE_DIR', 'W');
    TXT_LINE: = TAB_DDL; - TAB_DDL I get it from get_DLL (table, 'table_name') select of the double;
    UTL_FILE. PUT_LINE (F, TXT_LINE);
    UTL_FILE. NEW_LINE (F, 1);

    The prob that the foregoing is a failure when TAB_DDL return a big DOF.

    Any suggestions?


    Kind regards

    http://saubbane.blogspot.com/2011/03/generating-scripts-using-dbmsmetadata.html

  • Help! Trying to write an array to a file without having to rewrite the old data each time.

    Hey everybody,

    I have a vi that takes a 2D array and writes to an xml file. The purpose for this is to characterize the pathloss through a matrix dowkey 10 x 10 to different frequencies. I use this program to create a table of correspondence for the switching matrix, so when I make one of my tests I can get an accurate measurment. The problem with this is that I take data points about 299 by combination of matrix switches leading me to data more than 32000 points in the lookup table. I use xml because each data point requires a header so I can analyze via the table of correspondence with another of my vi when I need that pathloss. What I'm trying to fix, is that when my vi wrote in a file at a time to save memory space, he wrote a single Bay. When writing, it rewrites the old data, and then the new data. As the number of points of data increase so does the time of latency of writing in the file. At the time wherever I am finished, it takes about five hours to completely write to the file. Does anyone know how to write about writing to a file without having to rewrite all the old data? Attached, it's my vi to write to the file, my vi for research in the file and an example of one of my tables in research.

    Thank you

    Dustin

    Hello

    Just in case others have a problem, something along these lines as one excerpt:

  • Extract strings in the tdms files and write the strings in the file txt or lvm

    Hi all

    I'm struggling to extract strings from a file of tdms to write them in a txt file.

    The strings were written in tdms is a time stamp data recorded to a compact RIO.

    I put the chain in a different group from the PDM, but when I use the function read tdms with the group name, as I said, an error message is always take place.

    Thanks for all the help.

    PS: I have attached an example of tdms file I got over here.

    Kind regards

    Yifeng

    I tried your attached file and it seems that everything goes file. I have attached the screenshot of my VI here, what do you want?

  • While I'm trying to remove the MPEG-4 file, it says "make sure that the disk is not full or write protected and that the file is not currently in use.

    Original title: When I'm trying to delete file MPEG4, is not deletion. How can I delete file MPEG4?

    While I'm trying to remove the MPEG-4 file, it says "make sure that the disk is not full or write protected and that the file is not currently in use.

    Hello
     
    Method 1: Ownership of the file and then try to delete and see if that helps.
    Reference:
    How to capture a file or a folder in Windows XP
    http://support.Microsoft.com/kb/308421
    Method 2:
     
    Error message when you try to delete a file in Windows XP: "access denied".

    http://support.Microsoft.com/kb/298345

  • I need to remove the uneeded files: Purenetworks and PCFix. But I get: not deletenmrsrc.dll: access denied make sure the disk is not full or write protected and that the file is not in use.

    Original title: remove unnecessary files

    I need to remove the uneeded files: Purenetworks and PCFix. But I get: not deletenmrsrc.dll: access denied make sure the disk is not full or write protected and that the file is not in use.

    Ditto for PCFIX.exe.

    How can I remove these and clean unnecessary files? Thank you.

    Hello

    1. how exactly you are trying to remove it?
    2 have you connected the administrator account?

    Step 1: Check if the problem persists in the clean boot state.

    From your computer by using a minimal set of drivers and startup programs so that you can determine if a background program is interfering with your game or program. This type of boot is known as a "clean boot".

    Reference:

    How to configure Windows XP to start in a "clean boot" State

    http://support.Microsoft.com/kb/310353

    When you are finished troubleshooting, follow these steps to reset the computer to start as usual:

    1. click on start and then click Run.

    2. type msconfig and click OK.

    The System Configuration Utility dialog box appears.

    3. click on the tab general, click Normal Startup - load all services and device drivers and then click OK.

    4. When prompted, click on restart to restart the computer.

    Step 2: Take possession of these program at the following location folder, and then check the issue. C:\Program Files\ 

    Reference: How is ownership of a file or a folder in Windows XP

  • Write a bitmap to a file *.bmp or *.png with JDE 4.5

    Does anyone know a function to write a bitmap to a file standard riphics for example *. BMP *. PNG or something like that?

    I'm Trying with JDE 4.5 on the default curve Simulator.

    Please see this thread.

    http://supportforums.BlackBerry.com/Rim/Board/message?board.ID=java_dev&message.ID=736&query.ID=1057...

  • Write in an external xml file

    OK, so ive been reading on xml and found theres this big thing appeal. appendChild(). that let your add a node to an xml file.

    Here's the catch, I can write in an external xml file, without the need to load it, DIRECTLY through flex?

    or I have to use some php i.e. backend


    Thanks heaps!

    ojk007

    The Flash Player, when it is hosted by a browser, severely limits access to the resources of the host computer. In other words, you cannot read and write files. If the XML file resides on the server, then you can use the code server-side (e.g. PHP) and edit the file, or you can load the XML file into your Flex application on the client computer, change it, then refer to something that can write the file.

  • Write database Variables in the file

    Hello

    I try to write data values to a file.

    Assuming that I put
    getDatabank("205Comp").getNextDatabankRecord ();

    and there is a column field in the file called Agt_ID

    I thought I'd be able to write
    utilities.getFileService () .appendStringToFile (fileLocation + file name, "Agent:" + "{{db.205Comp.Agt_ID}}" + "things more" + "\n");
    to add value.

    However, this puts the line
    Agent: {db.205Comp.Agt_ID} more things
    in the file instead of the data.

    The following statement works very well, so I expect this work.
    Info ("Agent:" + "{{db.205Comp.Agt_ID}}");

    How can I write the value of data in the file?

    Thank you very much
    Neil

    Neil

    I know the code you wrote for work, but if not you can try this instead:

    utilities.getFileService () .appendStringToFile (fileLocation + file name, "Agent:" + eval ("{{db.205Comp.Agt_ID}}") + "things more" + "\n");

    Concerning

    Alex

  • How to write the CLOB parameter to a file or a XML using shell script?

    I run an oracle stored procedure using shell script. How can I get the OUT of the procedure (CLOB) parameter and write it to a file or a XML in UNIX environment using shell script?
    Edit/Delete Message
    SQL> var c clob
    SQL>
    SQL> begin
      2          select
      3                  DBMS_XMLGEN.getXML(
      4                          'select rownum, object_type, object_name from user_objects where rownum <= 5'
      5                  ) into :c
      6          from    dual;
      7  end;
      8  /
    
    PL/SQL procedure successfully completed.
    
    SQL>
    SQL> set long 999999
    SQL> set heading off
    SQL> set pages 0
    SQL> set feedback off
    SQL> set termout off
    SQL> set trimspool on
    // following in the script is not echo'ed to screen
    set echo off
    
    spool /tmp/x.xml
    select :c from dual;
    spool off
    
    SQL>
    SQL> --// file size
    SQL> !ls -l /tmp/x.xml
    -rw-rw-r-- 1 billy billy 583 2011-12-22 13:35 /tmp/x.xml
    
    SQL> --// file content
    SQL> !cat /tmp/x.xml
    
    
     
      1
      TABLE
      BONUS
     
     
      2
      PROCEDURE
      CLOSEREFCURSOR
     
     
      3
      TABLE
      DEPT
     
     
      4
      TABLE
      EMP
     
     
      5
      TABLE
      EMPTAB
     
    
    
    SQL> 
    
  • Cannot write IPTC metadata to JPG files

    I tried to write IPTC metadata to files JPG and I

    None of the original files have been modified

    Opening was not able to edit one or more original files because they have a format that does not allow editing.

    I found some old posts saying that it was fractured in Leo.

    Anyone have any ideas?

    What version of Aperture do you use?

    Your HABITAT are referenced?  You receive the error message even if the referenced original is not found. Try to export the original file to check, if it is available.

  • write the size of measurement files

    Hello

    I save a lot of data in my controller and you want to write to a file measure tdms format.

    the problem is that the files are very large, if I use the "write to file measure" - on purpose - vi.

    If I use the 'writing TDMS' - function instead, the files are much smaller, with almost the same parameters.

    Is it possible to use the Express VI with the same efficiency, if I used the "writing TDMS" - function?

    Why are large files if I have the express vi?

    In general, avoid using express screws they tend to be just something you can put down and quickly have something that will work.  They also tend to be inefficient.  In the case of write it to a file as it opens and closes the file whenever you call.  With PDM, which causes a lot of overhead in the file.  If you were doing a Defrag TDMS on each of your two files, it should come out pretty much the same size.

  • How to write Modbus data in a file or a matrix?

    Hello:

    I can monitor my data through RS-485 port using 'Master Series MB query', and successfully, I can show signals using the waveform.

    But I can't save the data during the test in a table or write to a file. (see attachment and picture)

    How can I write them to a file or a spreadsheet correctly?

    When I try to read 'file as' and this graph, I can not every graph, there simply a knot!

    is the data type "registers entry" needs a special procedure?

    What is the problem?

    Thank you.

    A fundamental flaw that I see is that you have to write file as configured to rename and replace any existing file when you call the function.

  • Can I choose when I want to write my data in a file?

    What I want is like,
    When I click a button as ON the then only will it a written data in a spreadsheet.

    Now, I did the bolllean so that it displays TRUE when you need to write... but if FALSE, nothing happens...
    and I don't see any option in writing to the spread for that worksheet function it...
    If you can help me on what I do

    ?

    You're writing the worksheet file in a case structure.

    I recommend you watch the LabVIEW tutorials online
    LabVIEW Introduction course - 3 hours
    LabVIEW Introduction course - 6 hours

Maybe you are looking for

  • Mac OS sierra app is damaged

    Hello I tried several times to download the operating system, but every time I get message This copy install macOS Sierra.app application is damaged and cannot be used to install macOS. I confirmed that I have enough RAM and disk space when the downl

  • concatenate a hexadecimal string

    I'm trying to communicate through a circulation bath series, but it requires that all orders as a hexadecimal string.  I generate a portion of the string as a constant, but I need to convert a decimal point and add it at the end of the string.  I can

  • I want to clean the print head using the head cleaning utility tab?

    I remove appearance of horizontal bands

  • SBH20 impossible to adjust the volume upward or downward

    Everything is normal with the Xperia C3 for playing music and talking on the phone, but just unable to adjust the volume upward or downwards by volume of SBH20 keys... All solutions?

  • Disable CTRL + ALT + DELETE to open

    Original title: when you connect I don't want to have to use Ctrl alt delete when I try to log in. How can I disable this feature? Help! Thanks, pete