• <tfoot id='ftva6'></tfoot>

      <i id='ftva6'><tr id='ftva6'><dt id='ftva6'><q id='ftva6'><span id='ftva6'><b id='ftva6'><form id='ftva6'><ins id='ftva6'></ins><ul id='ftva6'></ul><sub id='ftva6'></sub></form><legend id='ftva6'></legend><bdo id='ftva6'><pre id='ftva6'><center id='ftva6'></center></pre></bdo></b><th id='ftva6'></th></span></q></dt></tr></i><div id='ftva6'><tfoot id='ftva6'></tfoot><dl id='ftva6'><fieldset id='ftva6'></fieldset></dl></div>
      <legend id='ftva6'><style id='ftva6'><dir id='ftva6'><q id='ftva6'></q></dir></style></legend>

      <small id='ftva6'></small><noframes id='ftva6'>

          <bdo id='ftva6'></bdo><ul id='ftva6'></ul>
      1. oracle中的base64编解码

        时间:2023-09-20

        • <bdo id='kO4zj'></bdo><ul id='kO4zj'></ul>

        • <small id='kO4zj'></small><noframes id='kO4zj'>

          <i id='kO4zj'><tr id='kO4zj'><dt id='kO4zj'><q id='kO4zj'><span id='kO4zj'><b id='kO4zj'><form id='kO4zj'><ins id='kO4zj'></ins><ul id='kO4zj'></ul><sub id='kO4zj'></sub></form><legend id='kO4zj'></legend><bdo id='kO4zj'><pre id='kO4zj'><center id='kO4zj'></center></pre></bdo></b><th id='kO4zj'></th></span></q></dt></tr></i><div id='kO4zj'><tfoot id='kO4zj'></tfoot><dl id='kO4zj'><fieldset id='kO4zj'></fieldset></dl></div>
          <legend id='kO4zj'><style id='kO4zj'><dir id='kO4zj'><q id='kO4zj'></q></dir></style></legend>

                <tbody id='kO4zj'></tbody>

                • <tfoot id='kO4zj'></tfoot>
                  本文介绍了oracle中的base64编解码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如何在 Oracle 中对值进行 Base64 编码/解码?

                  How can I do Base64 encode/decode a value in Oracle?

                  推荐答案

                  我已经实现了这一点,以通过我的 MS Exchange 服务器发送西里尔文电子邮件.

                  I've implemented this to send Cyrillic e-mails through my MS Exchange server.

                  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;
                  

                  试试吧.

                  upd:经过微小的调整后,我想出了这个,所以现在它可以双向工作了:

                  upd: after a minor adjustment I came up with this, so it works both ways now:

                  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;
                  

                  你可以检查一下:

                  SQL> set serveroutput on
                  SQL> 
                  SQL> 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
                  

                  upd2: 好的,这里有一个适用于 CLOB 的示例转换,我刚刚想出了.尝试为您的斑点解决这个问题.:)

                  upd2: Ok, here's a sample conversion that works for CLOB I just came up with. Try to work it out for your blobs. :)

                  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;
                  

                  这篇关于oracle中的base64编解码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:以毫秒为单位计算 Oracle 中两个时间戳之间的差异 下一篇:ORA-12514 TNS:listener 当前不知道连接描述符中请求的服务

                  相关文章

                • <i id='ebWEQ'><tr id='ebWEQ'><dt id='ebWEQ'><q id='ebWEQ'><span id='ebWEQ'><b id='ebWEQ'><form id='ebWEQ'><ins id='ebWEQ'></ins><ul id='ebWEQ'></ul><sub id='ebWEQ'></sub></form><legend id='ebWEQ'></legend><bdo id='ebWEQ'><pre id='ebWEQ'><center id='ebWEQ'></center></pre></bdo></b><th id='ebWEQ'></th></span></q></dt></tr></i><div id='ebWEQ'><tfoot id='ebWEQ'></tfoot><dl id='ebWEQ'><fieldset id='ebWEQ'></fieldset></dl></div>

                  1. <small id='ebWEQ'></small><noframes id='ebWEQ'>

                    <legend id='ebWEQ'><style id='ebWEQ'><dir id='ebWEQ'><q id='ebWEQ'></q></dir></style></legend>
                      <bdo id='ebWEQ'></bdo><ul id='ebWEQ'></ul>
                  2. <tfoot id='ebWEQ'></tfoot>