Problem with my Base64 Encoding Routine CLOB.

I wrote a program that reads an xml file in the database
and makes Base64encoded.

We must work on 10g and above

If the length specified in the code below reading is greater than the length of the xml_file, and then I get the result (output) expected.

However if the playback time is less than the length of the file, then I get a lot of "is" in the file and, therefore, invalid, which means that the file is not readable by the application of encoding.
I'm sure I read the lengths of blob correctly, and the problem is somehow related to base64 encoding. Any help appreciated
[create or replace profile_dir as &profile_dir;
create global temporary table load_xml
(profile_text clob)
on commit delete rows;

create or replace
procedure encode_xml_clobs(p_file_in  in varchar2,
                             p_clob_out out nocopy clob )
 as
 pragma autonomous_transaction;
    dest_clob   CLOB;
    src_clob    BFILE  := BFILENAME('PROFILE_DIR', p_file_in);
    dst_offset  number := 1 ;
    src_offset  number := 1 ;
    lang_ctx    number := DBMS_LOB.DEFAULT_LANG_CTX;
    warning     number;
------------
-- processing declarations for encoding base64 --
v_xml_string varchar2(32767);
v_string varchar2(32767);
v_start_pos number := 0;
v_read_length number := 1000;
v_final_start_pos number;
v_clob_length number;
type clob_array_type is table of clob index by binary_integer;
clob_array clob_array_type;
v_index number :=0;
-- Declarations for converting base64encoded string to a clob
v_encoded_length number;
v_temp_clob clob;
BEGIN
    -- -----------------------------------------------------------------------
    -- THE FOLLOWING BLOCK OF CODE WILL ATTEMPT TO INSERT / WRITE THE CONTENTS
    -- OF AN XML FILE TO A CLOB COLUMN. IN THIS CASE, WE WILL USE THE NEW 
    -- DBMS_LOB.LoadCLOBFromFile() API WHICH *DOES* SUPPORT MULTI-BYTE
    -- CHARACTER SET DATA.
    -- -----------------------------------------------------------------------
-- load_xml should be a  Global temporary table with on commit delete rows 
    INSERT INTO load_xml(profile_text) 
        VALUES( empty_clob())
        RETURNING profile_text INTO dest_clob;

    -- -------------------------------------
    -- OPENING THE SOURCE BFILE IS MANDATORY
    -- -------------------------------------
    DBMS_LOB.OPEN(src_clob, DBMS_LOB.LOB_READONLY);

    DBMS_LOB.LoadCLOBFromFile(
          DEST_LOB     => dest_clob
        , SRC_BFILE    => src_clob
        , AMOUNT       => DBMS_LOB.GETLENGTH(src_clob)
        , DEST_OFFSET  => dst_offset
        , SRC_OFFSET   => src_offset
        , BFILE_CSID   => DBMS_LOB.DEFAULT_CSID
        , LANG_CONTEXT => lang_ctx
        , WARNING      => warning
    );
    DBMS_LOB.CLOSE(src_clob);
--    DBMS_OUTPUT.PUT_LINE('Loaded XML File using DBMS_LOB.LoadCLOBFromFile: (ID=1');
-- file now successfully loaded

select dbms_lob.GETLENGTH(profile_text)
into v_clob_length 
from load_xml;
-- File now loaded in temporary table
-- we now need to take the clob , convert it to varchar2
v_read_length :=64;
v_xml_string := '';
while v_start_pos <=  v_clob_length
loop
v_index := v_index + 1;
v_string := '';
--dbms_output.put_line('Start_pos=>'||(v_start_pos+1)||' Read Length=>'||v_read_length);
--encode base64 
select utl_raw.cast_to_varchar2(
utl_encode.base64_encode(
utl_raw.cast_to_raw(dbms_lob.substr(profile_text,least(v_read_length,v_clob_length-v_start_pos),v_start_pos+1))
))
  into v_string
  from load_xml;
--dbms_output.put_line(v_string);
v_start_pos  := v_start_pos+v_read_length;
clob_array(v_index) := v_string;
end loop;
p_clob_out := clob_array(1);
for i in 2 .. v_index
loop
dbms_lob.append(p_clob_out,clob_array(i));
end loop;
commit;
END;

Base64 encoding encodes each 3 bytes of input data in the 4 bytes of output data. She uses the equal signs to indicate nodata and at the end of the coded sequence. Try chaning your v_read_length setting to a multiple of 3 e.g. 960 or 1008 instead of the current 1000. I use multiples of 48 because the utl_encode.base64_encode function adds a linebreak for every 48 bytes of input data (64 bytes of output). If you use a value that is not divisible by 48, you will always get a legitimate coding, since it is divisible by 3, but you'll get a few lines more than others when you add them together.

Tags: Database

Similar Questions

  • Could not complete the command of video rendering due to a problem with Adobe Media Encoder.

    Hello, I use a macbook pro retina and before I was able to make the video without problem, and now it is popping up.  I tried to remove and reinstall photoshop, but it was not useful. I would appreciate help or advice.  Thank you!

    Here is the error message I get:

    Could not complete the command of video rendering due to a problem with Adobe Media Encoder.

    Maybe try to download from this line:

    https://creative.Adobe.com/products/Media-Encoder

    If this does not work, you might want to try reinstalling the Psalm

  • Problem with the length of a CLOB data type

    Hello

    In my application, I have a page with an interactive report of written blogs - on this page, you can add a new blog (text box - CLOB data type), discovered a blog or edit a blog.
    There is something going wrong with the size of the blog text. I know APEX cannot accept that 32K text and I've seen the great value saving thread, but this isn't the solution to my problem.

    The problem is that when I add a blog with say about 4000 characters, it is saved in the database, but the interactive report, when I click on the view or edit icons for this blog, the blog text field appears empty. For small items (< 4000 characters), there is no problem.
    Anyone know why this is happening and how to fix this?
    Thank you!

    There seems to be a bug in the calculation of the value of the element Source when the Source Type is a SQL query and the data type of the selected column is CLOB. I'll file a bug for this. For now, I have demonstrated how you can use a type of function PL/SQL source instead. Please see point P3_TEXT:

    beginfor c1 in (select blog_textfrom blogwhere blog_id = :P3_BLOG_ID) loop  return c1.blog_text;end loop;return null;end;
    

    Scott

  • Problem with printing using htp.prn CLOB

    Hello

    Oracel 11g R2
    Apex 4.1

    I got a reference from this forum on how to print the CLOB data using htp.prn.

    However, when I run my procedure, I get the error
     ORA-06502: PL/SQL: numeric or value error: character string buffer too small 
    The length of the clob is 195734.

    The code is
     
    
    CREATE OR REPLACE PROCEDURE nat_test_lsp_ws_3
    IS
    
       l_amt NUMBER DEFAULT 8191;
       l_offset NUMBER DEFAULT 1;
       l_length NUMBER DEFAULT 0;
       v_clob CLOB;
       
     
    BEGIN
    
    SELECT dbms_xmlgen.getxml('select * from table(pkg_bp_eisa.lsp_exa_ws(7))') into v_clob FROM dual;
     htp.htmlopen;
      htp.bodyopen;
      l_length := dbms_lob.getlength(v_clob);
      dbms_output.put_line('Length of Clob:='||l_length);
      IF l_length > 0 THEN 
      WHILE (l_offset < l_length)
      LOOP
       htp.prn(dbms_lob.substr(v_clob, l_amt, l_offset));
       l_offset := l_offset + l_amt;
      END LOOP;
      END IF;
      htp.bodyclose;
      htp.htmlclose;
      
    
    EXCEPTION
       WHEN OTHERS THEN
       dbms_output.put_line(dbms_utility.format_error_stack);
       dbms_output.put_line(dbms_utility.format_error_backtrace);
       RAISE;
    
    END;
    I get the error on line htp.prn...

    However, if the clob size is too small, it is printing. Are there no restrictions for the clob to print size?

    Thanks in advance.

    Kind regards

    Natarajan

    Natarajan,

    Your procedure works very well under the Express Application. If you run your procedure of SQL commands, no error is encountered. If you run it from SQL * more or outside of a context of APEX, then you will encounter the error you reported.

    To remedy the problem, add the following line in the first executable statement in your procedure:

    sys.htp.htbuf_len := 63;
    

    Joel

  • Problem with Adobe Media Encoder CS5.5

    Anyone has an idea why the windows input/output stopped displaying images?

    The preview as its encoding works very well


    See you soon,.


    Stu

    If you are on Mac, then this is the result of a change in OSX 10.7.3. See this thread: http://forums.adobe.com/message/4328310#4328310.

  • Problem with the XML encoding when displayed

    I had decided to use XML file instead of a database because the customer did not have a database is the web hosting package. But I have a weird problem where the information is not well displayed but they are well received! The french characters using client that the site is in french and English and special characters outside the first 128 characters of ASCII is not displayed correctly. I don't know exactly what to do at this level where the XML file is perfect (and I can see the special characters correctly). I tried to use the CFPROCESSINGDIRECTIVE but it did nothing for the correct display.

    If anyone has an idea while I'm looking always thought that the web something to solve this problem, please let me know.

    Here's an example of what I'm talking about:

    "Sled" is displayed "Traa® neau.

    I found out why! The original XML file has been modified manually and it screw the file for some reason any. When you use the process of creating the XML file and to use it after as it was created, all special characters are displayed correctly.

    In conclusion, never manually edit your XML file! ;-))

  • problem with the CLOB type

    Hello, I am a beginner, I have a problem with the CLOB type, please help me
    I want to write the input file is filename and string base64, then output decoded base64 content in dicrectory location (for example C:\),my code was executed but if entry with base64 long string, it displays error)
    ORA-29285: file write error
    ORA-06512: at "SYS.UTL_FILE", line 136
    ORA-06512: at "SYS.UTL_FILE", line 813
    ORA-06512: at "SYSTEM.WRITED", line 9
    ORA-06512: at line 1
    29285. 00000 -  "file write error"
    *Cause:    Failed to write to, flush, or close a file.
    *Action:   Verify that the file exists, that it is accessible, and that
               it is open in write or append mode.
    And this is my code
    create or replace directory dir_temp as 'C:\';
    /
    create or replace procedure writed(filename varchar2,code  clob)
    as
      f utl_file.file_type;
      v_lob          BLOB;  
    
    begin
      v_lob :=  UTL_ENCODE.BASE64_DECODE( UTL_RAW.CAST_TO_RAW(to_char(code)) ); 
      f := utl_file.fopen('DIR_TEMP', filename, 'w');
      utl_file.put_line(f,to_clob(utl_raw.cast_to_varchar2(v_lob)));  
      utl_file.fclose(f); 
    end;
    Thank you
    DBMS_XSLPROCESSOR.clob2file(
      cl => l_clob
    , flocation => 'XML_LOG'
    , fname => myfile_name
    );
    

    for example

    SQL> ed
    Wrote file afiedt.buf
    
      1  declare
      2    type t_emps is table of emp%ROWTYPE;
      3    v_emps    t_emps;
      4    --
      5    v_clob    clob;
      6    v_newline varchar2(2) := chr(13)||chr(10);
      7  begin
      8    -- get the rows into a PL/SQL collection of records
      9    select *
     10    bulk collect into v_emps
     11    from emp;
     12    -- build up the CLOB
     13    v_clob := 'EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO';
     14    for i in 1..v_emps.count
     15    loop
     16      v_clob := v_clob||v_newline||
     17                to_char(v_emps(i).empno,'fm9999')||','||
     18                v_emps(i).ename||','||
     19                v_emps(i).job||','||
     20                to_char(v_emps(i).mgr,'fm9999')||','||
     21                to_char(v_emps(i).hiredate,'YYYYMMDD')||','||
     22                to_char(v_emps(i).sal,'fm99999')||','||
     23                to_char(v_emps(i).comm,'fm99999')||','||
     24                to_char(v_emps(i).deptno,'fm99');
     25    end loop;
     26    -- write the CLOB to a file
     27    DBMS_XSLPROCESSOR.clob2file(cl => v_clob, flocation => 'TEST_DIR', fname => 'myfile.csv');
     28* end;
    SQL> / 
    
    PL/SQL procedure successfully completed.
    
  • Problems with encoder motor switching noise readings

    Hi all

    I wanted to ask advice with a hardware problem which seems to be pretty common.

    Here I describe my request:

    We are controlling an electric actuator for robotics application. We use encoders to take position readings, and we need to perform analog acquisition for other measures (for example, the force measured using strain gauges).

    The problem is:

    In summary, I have problems to properly acquire position readings of a linear encoders quadrature and also a few analog inputs. The cause is the switching noise generated by the drive motor that we use (which is an engine without Stricker of CC Moog BN-23-23).

    Our acquisition platform is an NI PXI-8106 with a PXI-1042 q chassis. We have two possibilities to acquire the signals. We have a multifunction DAQ series NI PXI-6259 M and a FlexRIO NI PXI-7951R with one module DIO NI PXI-6581R.

    The switching noise have a frequency of 30 kHz. In a scope, we see a series of peaks of noise which are present only during a short period of time (approximately 1/10th of the duration of the noise). The rest of the time the noise is not present.

    The Accelnet amplification module that powers the electric motor gives us a clock signal synchronized with the noise (whose frequency is approximately 1/4 frequency noise). This clock signal provides a way to solve the problem of analog acquisition. We can use this clock to make an acquisition stamped with an external clock in LabView connecting the clock on a spit of PFI or FPGA card. But the noise is also corrupt this clock signal (we get an error daqmx us warning of possible defects in the clock signal and also to stop the acquisition). I believe that to solve the problem of encoder we can also solve the problem of the analog acquisition.

    In the encoder readings noise makes our County to counter upward or backward gradually fast enough. We can get an increase in the position of about 10 cm per second with no appreciable movement in the linear actuator.

    It would be a great help if someone could put the solution he uses to solve this problem.

    Thanks in advance for your help,

    jespestana

    PS: I stress my conviction that we have a hardware problem, because we have only bad readings when the electric motor does not work. I am therefore convinced because we have already done reading encoder and analog with the help of other players, such as hydraulic cylinders. So, I think that it is not a problem with our software (of our LabView VI).

    Hi jespestana,

    I don't know why the noise could be the cause of your encoder can increase more slowly...  However I have a suggestion on the map of the M series (6259):

    M-series cards have a digital filter integrated on the lines of the PFI (see the user manual of M series).  Looks like the noise is a series of 3 ~ US of impulses (1/10 to 1/30 kHz).  Of the available filtering frequencies that you can set on your M series is 6,425 US, which must ignore the impulses (high or low) that are less than 6,425 US. You can configure the digital filtering with a property node DAQmx:

    One caveat is that the driver only allows you to configure the digital filtering for entries counter on M Series devices.  For example, you can use a digital filtering directly on your task of encoder, but not for your sample clock HAVE.  A workaround can be found here, which is to set up a dummy counter job to define the PFI filter for your task to HAVE.  If you use the same PFI line for your encoder and the task to HAVE it, you should be able to just set up the PFI filter through the task of the encoder and worry for the workaround.

    Regarding the RIO Flex, I think that you could implement something similar on the FPGA, but I'm probably not the best person to comment on this subject.  It would be probably a lot more work to use the DAQmx API's built-in filtering.

    Best regards

  • Windows Media Player for Vista - problem with encoding

    I'm unable to access the auxiliary encoder Windows Media (WMPEnc.exe) to solve a problem with a Windows Media Player.  I've always been able to convert video files to a portable device and now I have a message that an "unsupported format" is detected.  The player has been bunddled with Windows Vista, so I can't uninstall / reinstall without a full restore of Windows. Have uninstalled/reinstalled that the software of the device, but still does not work.  I hope someone can help.

    Please repost your question in images and video Forum at: http://social.answers.microsoft.com/Forums/en-US/vistapictures/threads where experts in Media Player will be happy to help you.

    Good luck!

    Lorien - MCSA/MCSE/network + / has + - if this post solves your problem, please click the 'Mark as answer' or 'Useful' button at the top of this message. Marking a post as answer, or relatively useful, you help others find the answer more quickly.

  • Internal CLOB.getAsciiStream in GR 11, 2 problem with temp CLOB JVM

    Hello

    I have a problem with the help of a temporary CLOB in PL/SQL that will be written with the Java Code that runs inside the Oracle (internal JVM) database. The code works without problem in Oracle 11 g R1 (11.1.0.7.0) but not with Oracle 11 g R2 (12.2.0.1.0). The example follows:

    < b > Table Description: < /b >

    NAME Null? Type
    ------------------------------- --------- -----
    ID NOT NULL NUMBER(*,0)
    TYPE_DE_FICHIER NOT NULL NUMBER(*,0)
    INSERT_DATE NOT NULL DATE
    NUMBER(*,0) NULL UNPROCESSED
    LFIELD001 CLOB (4000)
    BFIELD001 BLOB (4000)
    FILE_NAME VARCHAR2 (4000)


    < b > PL/SQL example Run: < /b >

    DECLARE
    CLB CLOB.
    p_result NUMBER; p_err VARCHAR2 (4000);
    t the BLOB;
    BEGIN
    SELECT bfield001
    T
    OF file_data
    ID WHERE = 200;

    CTR: = java_utils.clob_zipdecompress (t, 'BANKFILE_', p_result);

    -The output results
    dbms_output.put_line (SubStr ('p_result =' |)) To_char (p_result), 1, 255));
    dbms_output.put_line (SubStr ('p_err =' | p_err, 1, 255));
    dbms_output.put_line (SubStr ('p_return_clob =' |)) SUBSTR (CTR, 1 255), 1, 255));
    END;


    < b > example < /b > package
    PACKAGE JAVA_UTILS
    IS
    -Unzip a BLOB in format ZIP to a CLOB and return it with the file name specified figure
    FUNCTION clob_zipdecompress (p_blob IN BLOB, p_fname IN VARCHAR2, p_result OUT NUMBER)
    CLOB RETURN;


    END JAVA_UTILS;

    JAVA_UTILS PACKAGE BODY
    IS

    -Unzip a BLOB in format ZIP to a CLOB and return it with the file name specified figure
    FUNCTION clob_zipdecompress (p_blob IN BLOB, p_clob IN CLOB, p_fname IN VARCHAR2)
    RETURN NUMBER
    AS the JAVA LANGUAGE NAME "java_utils.Compress.ZipDecompress (oracle.sql.BLOB, oracle.sql.CLOB, java.lang.String) return int";

    FUNCTION clob_zipdecompress (p_blob IN BLOB, p_fname IN VARCHAR2, p_result OUT NUMBER)
    RETURN THE CLOB
    IS
    l_clob CLOB. l_result NUMBER;
    BEGIN
    IF p_blob IS NULL THEN
    RETURNS A NULL VALUE.
    END IF;

    DBMS_LOB.CREATETEMPORARY (l_clob, TRUE);
    p_result: = clob_zipdecompress (p_blob, l_clob, p_fname);

    RETURN l_clob;
    END clob_zipdecompress;
    END JAVA_UTILS;



    < b > function < /b > simplified example Java

    package java_utils;
    import java.lang. *;
    Oracle.sql import. *;
    import java. IO;
    java.util.zip import. *;
    public class Compress
    {
    /**
    * Uncompresses the BLOB in CLOB
    *
    @param blob the BLOB source (compressed binary data)
    @param clob CLOB target (hold plain text), it should be an empty CLOB recovered for
    example with dbms_lob.createtemporary (l_clob, true);
    * @throws exception for most of I/O exceptions if ever
    */
    public static int ZipDecompress (String fname, String [] err, BLOB, CLOB clob blob object)
    {
    OutputStream out; ZipInputStream z; Ze ZipEntry. String zeName; Byte [] buffer; int cnt;
    Boolean found = false;

    try {}
    out = clob.setAsciiStream(0L); Here, it fails
    }
    catch (Exception ex) {err [0] = ex.getMessage (); return-1 ;}}

    return 0;
    }


    }



    Running the example works well when 11 GR 1 material but 11 GR 2 returns an error: < b > not valid or the arguments in the call. < /b >


    No idea why this is happening?
    Any help will be appreciated.

    Ms.

    Hi MS:
    Replace:
    clob.setAsciiStream(0L); Here, it fails
    by:
    clob.setAsciiStream(1L);
    the CLOB Api went from quick implementation of Oracle to the implementation of the standard.
    HTH, Marcelo.

  • Problem with CLOB in CF8 and Oracle 11.2.0.3

    I just noticed a problem with recovery CLOB in my ColdFusion applications. Any query that should return a CLOB suddenly returns an empty string. I noticed short time after upgrading to Oracle 11.2.0.2 to 11.2.0.3. My best guess is that we use the version 3.6 driver. I noticed on the DataDirect web site, they list support for Oracle 11 g for version 3.7, but I don't see any reference to 3.7 on the Adobe Web site so I don't know if I can switch to it.

    I don't really know if the point Oracle version upgrade was what caused it or not. Has anyone else encountered this problem?

    Upgrade to CF9 seems to have solved the problem. I don't know what component caused the problem, however.

  • Problem with the CLOB data type.

    Greetings,

    I am facing a problem with the CLOB data type. I know that the CLOB data type is 4 GB (I use Oracle 9i). But in the Pl Sql procedure, I can only store 34305 size for a CLOB variable character data.

    This is the test script that I am trying to run.

    DECLARE
    -Local variables here*.
    I have INTEGER;
    C_1 CLOB.
    BEGIN
    FOR Rec IN (SELECT
    *
    ACCORDING TO THE TABLE)
    LOOP
    C_1: = c_1 | Rec.Clo_1;
    END LOOP;
    EXCEPTION
    WHILE OTHERS THEN
    Dbms_Output.put_line (SQLERRM);
    END;


    Here variable C_1 range value 34305 good character regardless of type CLOB. Now the above script fails if query my buckle - huge number of return values. It is throwing the exception "error during transfer of files ORA-06502: PL/SQL: digital error or value."

    He would be grateful if someone can help me on this.

    Thank you.

    You are probably better off using DBMS_LOB.append, instead of the concatenation of varchar2 (|).

    And... take off your when-other Manager exceptions, please...

  • Problem with Demo_Mail package sending an attachment and special characters

    Hello

    I did use the Demo_Mail package with the example in the http://www.oracle.com/technology/sample_code/tech/pl_sql/htdocs/Utl_Smtp_Sample.html for many years on my 9i database.

    Recently, we have taken a form that depends on this package and quickly found that Asian characters were not correctly in the e-mail subject or body. When I changed the procedure by example, characters came through, however, attachments now appear in the body of the email as ascii.

    /*------------------------------------------------------start the email creation--------------------------------------------------------------------*/
    Conn: = demo_mail.begin_mail)
    sender = > from_name,.
    recipient = > to_name,.
    subject = > subject,.
    mime_type = > "text/plain; charset = utf8');

    () demo_mail.write_mb_text
    Conn = > conn,.
    message = > message | UTL_TCP. CRLF);

    If file1 is not null
    then
    () demo_mail2.begin_attachment
    Conn = > conn,.
    mime_type = > ' application/octet-stream. "
    Online = > FALSE,
    v_filename = > file1.
    transfer_enc = > 'base64');

    file_len: = dbms_lob.getlength (wire);
    modulo: = mod (file_len, TN);
    parts: = trunc(file_len / amt);


    / * (dbms_lob.read (wire, amt, filepos, buf); * /)


    While (counter < = pieces) LOOP

    DBMS_LOB. Read (wire, amt, filepos, buf);
    demo_mail.write_raw (conn, utl_encode.base64_encode (buf));
    filepos: = counter * TN + 1;
    counter: = counter + 1;

    END LOOP;

    / * Point on the rest of the data buffer * /.
    IF (modulo <>0) then
    DBMS_LOB. Read (wire, modulo, filepos, buf);
    demo_mail2.write_raw (conn, utl_encode.base64_encode (buf));
    end if;

    () demo_mail.end_attachment
    Conn = > conn);
    end if;

    () demo_mail.end_mail
    Conn = > conn);
    /*------------------------------------------------------end the email creation--------------------------------------------------------------------*/


    How can I have my cake and eat it too? Examples of scripts showing this scenario exist?

    In addition, even if I was able to get the body of the email to display special characters, the subject line still displays question marks instead of the special characters. I was never able to solve this problem.

    Any help to any of these questions is greatly appreciated!

    Thank you

    Kim

    You use the utl_encode.quoted_printable_encode before making all these changes? Most, if not all, of these accented characters must be converted to quoted printable form by the utl_encode.quoted_printable_encode function, then you only need to focus on the specific characters that must be encoded to the channel to cover additional expenditures for the mimeheader encoding. Specifically the white space characters should be encoded as well as the question mark.

    Also, I have done some minor testing and it seems that the quoted_printable_encode function folds the text when it exceeds a specific length. If I unfold the coded text object lines seem to come by fine. The folding text string is an equal sign followed by the sequence CRLF, unfold the text is a simple matter of these three characters. These changes becomes the encoding routine encapsulated in a function:

    create or replace function mimeheader_encode(
          p_str varchar2
        , p_charset varchar2 := 'UTF-8') return varchar2 is
      l_str varchar2(2000);
    begin
      l_str:=utl_raw.cast_to_varchar2(utl_encode.quoted_printable_encode(utl_raw.cast_to_raw(p_str)));
      l_str:=replace(l_str,'='||chr(13)||chr(10),''); --unfold the data
      l_str:=replace(l_str,'?','=3f'); --quote question marks
      l_str:=replace(l_str,' ','=20'); --quote spaces
      l_str:='=?'||p_charset||'?Q?'||l_str||'?='; -- add prefix and suffix
      return l_str;
    end;
    /
    
  • Problem with utl_smtp


    Hi all

    I am facing a problem with setting using utl_smtp, question is file BLOB does not as an attachment by e-mail to place the content of the BLOB is embedded in the body of the email. Here are my exact requirement:

    (1) send emails with UTL_SMTP

    (2) get the BLOB of the fnd_lobs for a sales order table and fix it with the emai

    The above obligation, email is going very well for me, the only question I face is with an attachment. Here is the code I use for this requirement:

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

    DECLARE

    LONG l_to_list;

    l_date VARCHAR2 (255) DEFAULT TO_CHAR (SYSDATE, "dd my hh24:mi:ss yy");

    l_crlf VARCHAR2 (2): = CHR (13) | CHR (10);

    l_profile_value VARCHAR2 (300);

    l_from_profile_value VARCHAR2 (300);

    l_mailhost VARCHAR2 (300);

    l_lemail2 VARCHAR2 (2000);

    l_dlimiter_cnt NUMBER (10): = 0;

    l_lemail_adr VARCHAR2 (2000);

    l_strnl NUMBER: = 0;

    l_emailids VARCHAR2 (1000);

    l_emailid VARCHAR2 (1000);

    l_user_id NUMBER;

    l_resp_id NUMBER;

    l_resp_appl_id NUMBER;

    l_dup_email_exist_cnt NUMBER;

    l_recipients VARCHAR2 (4000);

    l_subject VARCHAR2 (4000): = 'this is a Test Email ";

    l_html_content VARCHAR2 (1): = 'n';

    l_mail_conn UTL_SMTP.connection;

    l_email_addr VARCHAR2 (50): ='[email protected] ';

    l_content VARCHAR2 (1000): = 'Test Email ';

    g_crlf CHAR (2) DEFAULT CHR (13) | CHR (10);

    l_bcc VARCHAR2 (50): ='[email protected] ';

    v_raw raw (57);

    V_LENGTH INTEGER: = 0;

    v_buffer_size INTEGER: = 57;

    v_offset INTEGER: = 1;

    l_attach_blob BLOB;

    p_filename VARCHAR2 (50): = "QUOTE_REPORT_11122113.pdf";

    MAX_BASE64_LINE_WIDTH CONSTANT PLS_INTEGER: = 76 / 4 3;

    i                     NUMBER               :=1;

    l_boundary VARCHAR2 (50): = '-= * #abc1234321cba #* =';

    l_step PLS_INTEGER: = 24573;

    l_length PLS_INTEGER;

    l_begin PLS_INTEGER: = 1;

    l_buffer_size INTEGER: = 75;

    l_raw RAW (32767).

    BEGIN

    SELECT file_data

    IN l_attach_blob

    OF fnd_lobs

    WHERE file_id = 1016452;

    dbms_output.put_line ('Content of msg is' | l_content);

    --==========================================================

    -Assiginh the host dynamically through profile name

    --==========================================================

    l_profile_value: = fnd_profile. VALUE ("GLOBAL_HOST_NAME");

    dbms_output.put_line ('hostname' | l_profile_value);

    l_mailhost: = l_profile_value;

    dbms_output.put_line ('hostname' | l_mailhost);

    --==========================================================

    -Assiginh profile dynamically through the email address

    --==========================================================

    l_from_profile_value: = fnd_profile. VALUE ("FROM_PROFILE");

    dbms_output.put_line ('hostname' | l_from_profile_value);

    --=================================================================

    -Based on the e-mail profile process global value launch UTL_SMTP

    --=================================================================

    l_mail_conn: = UTL_SMTP.open_connection (l_mailhost, 25);

    UTL_SMTP. HELO (l_mail_conn, l_mailhost);

    UTL_SMTP.mail (l_mail_conn, l_from_profile_value);

    UTL_SMTP. RCPT (l_mail_conn, l_email_addr);

    UTL_SMTP. RCPT (l_mail_conn, l_bcc);

    -l_to_list: = ' from: '. l_email_addr;

    UTL_SMTP.open_data (l_mail_conn);

    UTL_SMTP.write_data (l_mail_conn, ' Date: ' |) TO_CHAR (SYSDATE, ' ' DD-MON-YYYY HH24:MI:SS) | UTL_TCP. CRLF);

    UTL_SMTP.write_data (l_mail_conn, ' from: ' | l_email_addr |) UTL_TCP. CRLF);

    UTL_SMTP.write_data (l_mail_conn, ' from: ' | l_from_profile_value |) UTL_TCP. CRLF);

    UTL_SMTP.write_data (l_mail_conn, ' BCC: ' | l_bcc |) UTL_TCP. CRLF);

    UTL_SMTP.write_data (l_mail_conn, ' subject: ' | l_subject |) UTL_TCP. CRLF);

    UTL_SMTP.write_data (l_mail_conn, ' Reply-To: ' | l_from_profile_value |) UTL_TCP. CRLF. UTL_TCP. CRLF);

    UTL_SMTP.write_data (l_mail_conn, l_content |) UTL_TCP. CRLF. UTL_TCP. CRLF);

    -UTL_SMTP.write_data (l_mail_conn, ' Content-Type: ': ' text/plain "|") UTL_TCP. CRLF);

    UTL_SMTP.write_data (l_mail_conn, ' Content-Disposition: attachment ;'||) UTL_TCP. CRLF |' filename = ' test po.pdf"' | UTL_TCP. CRLF);

    UTL_SMTP.write_data (l_mail_conn, "Content-Transfer-Encoding: base64' |") UTL_TCP. CRLF);

    l_length: = dbms_lob.getlength (l_attach_blob);

    l_begin: = 1;

    l_raw: = NULL;

    l_buffer_size: = 75;

    All IN l_begin < l_length

    LOOP

    DBMS_LOB. Read (l_attach_blob, l_buffer_size, l_begin, l_raw);

    UTL_SMTP.write_raw_data (l_mail_conn, utl_encode.base64_encode (l_raw));

    UTL_SMTP.write_data (l_mail_conn, utl_tcp.crlf);

    l_begin: = l_begin + l_buffer_size;

    END LOOP;

    UTL_SMTP.write_data (l_mail_conn, UTL_TCP.crlf |) UTL_TCP. CRLF);

    UTL_SMTP.write_data (l_mail_conn, '-' | l_boundary |) '--' || UTL_TCP. CRLF);

    UTL_SMTP.write_data (l_mail_conn, utl_tcp.crlf);

    UTL_SMTP.close_data (l_mail_conn);

    UTL_SMTP. Quit (l_mail_conn);

    EXCEPTION

    WHILE OTHERS THEN

    dbms_output.put_line ('Exception occurred' |) SQLERRM);

    END;

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

    Ask you to provide your entries as soon as possible.

    Thank you

    You must add a forward limit of attachment, like this:

    UTL_SMTP.write_data (l_mail_conn, '-' | l_boundary |) UTL_TCP. CRLF);

    UTL_SMTP.write_data (l_mail_conn, ' Content-Disposition: attachment ;'||) UTL_TCP. CRLF |' filename = ' test po.pdf"' | UTL_TCP. CRLF);

    UTL_SMTP.write_data (l_mail_conn, "Content-Transfer-Encoding: base64' |") UTL_TCP. CRLF);

    UPD: removed extra '-'

  • Problem with Chrome and El Capitan 10.11.4 fonts?

    I have a strange problem with Chrome v 49.0.2623.87 after upgrade to Mac OS X 10.11.4. On various e-commerce sites, including amazon and eBay, Staples, screen fonts are missing. I know this is usually related to the chromium does not correctly defined in the encoding preferences. I tried different settings, but nothing has worked. Does anyone have a solution?

    I think you need to take your question on the Google Chrome help Forum.  Because Chrome is not an Apple application, all the problems that you experience relating to it and OS X will have to be resolved by them.

Maybe you are looking for

  • can I put a disc more into my imac 2009?

    My wife has an iMac (2009) vintage with a hard drive internal 640 G which is fill to the top. She wondered if it can replace it with a larger drive, and if it is not a useful expenditure. (The computer plays very well this time, incidentally.) Any re

  • Version mismatch - Lenovo Twist

    I couldn't find a category for this machine, so I thought I would post it to the closest thing that I could think of. We just bought a Lenovo Twist and we receive an error on the machine when we record saying: Version mismatch. Update the parameters

  • The memory could not be "read".

    I'm game, and it was show below. How to solve it? [The instruction at "0x10073f24" referenced memory at "0x0d8e91b8". The memory could not be "read".] [Click on OK to terminate the program] Help, please

  • Automatic EA6500 for PokerStars port forwarding

    When I play poker online I am sometimes disconnected. The network status report showed that it is because of my router. They recommended that do the following: Please set the trigger (automatic port forwarding) for the following ports: 26002 and 443

  • Used to read external hard drive

    Hi there, my external hard drive read fine on my old xp computer and it works on other opportunities that I tried to use it but for some reason any that it does not work on my computer.  It says ACCESS DENIED.  I tried everything I could think of.  I