Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've implemented this to send Cyrillic e-mails through my MS Exchange server.</p> <pre><code>function to_base64(t in varchar2) return varchar2 is begin return utl_raw.cast_to_varchar2(utl_encode.base64_encode(utl_raw.cast_to_raw(t))); end to_base64; </code></pre> <p>Try it.</p> <p><strong>upd:</strong> after a minor adjustment I came up with this, so it works both ways now:</p> <pre><code>function from_base64(t in varchar2) return varchar2 is begin return utl_raw.cast_to_varchar2(utl_encode.base64_decode(utl_raw.cast_to_raw(t))); end from_base64; </code></pre> <p>You can check it:</p> <pre><code>SQL&gt; set serveroutput on SQL&gt; SQL&gt; declare 2 function to_base64(t in varchar2) return varchar2 is 3 begin 4 return utl_raw.cast_to_varchar2(utl_encode.base64_encode(utl_raw.cast_to_raw(t))); 5 end to_base64; 6 7 function from_base64(t in varchar2) return varchar2 is 8 begin 9 return utl_raw.cast_to_varchar2(utl_encode.base64_decode(utl_raw.cast_to_raw (t))); 10 end from_base64; 11 12 begin 13 dbms_output.put_line(from_base64(to_base64('asdf'))); 14 end; 15 / asdf PL/SQL procedure successfully completed </code></pre> <p><strong>upd2:</strong> Ok, here's a sample conversion that works for <code>CLOB</code> I just came up with. Try to work it out for your blobs. :)</p> <pre><code>declare clobOriginal clob; clobInBase64 clob; substring varchar2(2000); n pls_integer := 0; substring_length pls_integer := 2000; function to_base64(t in varchar2) return varchar2 is begin return utl_raw.cast_to_varchar2(utl_encode.base64_encode(utl_raw.cast_to_raw(t))); end to_base64; function from_base64(t in varchar2) return varchar2 is begin return utl_raw.cast_to_varchar2(utl_encode.base64_decode(utl_raw.cast_to_raw(t))); end from_base64; begin select clobField into clobOriginal from clobTable where id = 1; while true loop /*we substract pieces of substring_length*/ substring := dbms_lob.substr(clobOriginal, least(substring_length, substring_length * n + 1 - length(clobOriginal)), substring_length * n + 1); /*if no substring is found - then we've reached the end of blob*/ if substring is null then exit; end if; /*convert them to base64 encoding and stack it in new clob vadriable*/ clobInBase64 := clobInBase64 || to_base64(substring); n := n + 1; end loop; n := 0; clobOriginal := null; /*then we do the very same thing backwards - decode base64*/ while true loop substring := dbms_lob.substr(clobInBase64, least(substring_length, substring_length * n + 1 - length(clobInBase64)), substring_length * n + 1); if substring is null then exit; end if; clobOriginal := clobOriginal || from_base64(substring); n := n + 1; end loop; /*and insert the data in our sample table - to ensure it's the same*/ insert into clobTable (id, anotherClobField) values (1, clobOriginal); end; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload